.htaccess opencart 重定向 301

发布于 2024-10-31 06:15:26 字数 2926 浏览 0 评论 0 原文

我刚刚将我的网站从 asp 迁移到 opencart。在 .htaccess 中,我想做一些重定向,以便我的客户可以使用旧链接来访问

.htaccess For Contact Us 内部,

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads

该链接工作完美,但是,对于下载网址,它无法正常工作。 当我访问 http://www.example.com/downloads.asp 时,它将重定向到 http://www.example.com/downloads?_route_=downloads.asp代码> 和 Opencart 显示找不到页面。 对于http://www.example.com/downloads,我们在后端系统中设置了 SEO 友好的 URL。

我们可以通过

http://www.example.com/information/downloads

http://www.example.com/downloads

但我们无法使用正常链接访问

http://www.example.com/index.php?route=information/downloads

以下是我完整的 .htaccess

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads

============另一个测试==========================

我对此做了一些测试我的本地主机我发现这是一个非常有趣的结果。然而我的问题还是没有解决。

我从 http://localhost/examplehttp://example(添加虚拟目录)

对于 http://localhost/example

redirect 301 /example/downloads.asp http://localhost/example/downloads/

对于 http://example

redirect 301 /downloads.asp http://example/downloads/

然后我尝试重定向到我的实时版本链接,从本地主机(http://example)

redirect 301 /downloads.asp http://www.example.com/downloads/

我访问http://example/downloads.asp

浏览器重定向到我

http://www.example.com/downloads?route=downloads.asp

注意

在LIVE版本中,我没有添加任何重定向代码[非常确定]

但在Live版本中,我要直接输入

http://www.example.com/downloads

我不确定为什么从 localhost 重定向 301 到 live 版本会出来

http://www.example.com/downloads?route=downloads.asp

有什么想法吗?

I just migrate my site from asp to opencart. In .htaccess I would like to do some redirect so that my customer can use back the old link to access

inside .htaccess

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads

For Contact Us that work perfectly, however, for the downloads url, it didn't work correct.
when I access to http://www.example.com/downloads.asp it will redirect to http://www.example.com/downloads?_route_=downloads.asp
and Opencart show it is page not found.
For the http://www.example.com/downloads we had set SEO friendly URL in the backend system.

We able to access with

http://www.example.com/information/downloads

http://www.example.com/downloads

but we not able to access with normal link

http://www.example.com/index.php?route=information/downloads

The folowing is my full .htaccess

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads

============ANOTHER TESTING========================

I did some testing on this on my localhost I found out it is a quit interesting result. However, my problem still haven't solve.

I run the .htaccess from http://localhost/example and http://example (added virtual directory)

For http://localhost/example

redirect 301 /example/downloads.asp http://localhost/example/downloads/

and

For http://example

redirect 301 /downloads.asp http://example/downloads/

Then I tried, redirect to my live version link, from localhost (http://example)

redirect 301 /downloads.asp http://www.example.com/downloads/

I access to http://example/downloads.asp

The browser redirect to me

http://www.example.com/downloads?route=downloads.asp

NOTED

In LIVE version, I did not added any redirect code [VERY SURE FOR THIS]

But in Live version, I am to access directly with enter

http://www.example.com/downloads

I am not sure why from localhost redirect 301 to live version will come out

http://www.example.com/downloads?route=downloads.asp

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坐在坟头思考人生 2024-11-07 06:15:26

找到解决方案:
.htaccess 重定向 301 与 opencart v1.5.4.1 配合使用

需要其他代码...(以及此修复的功劳):
https://github.com/opencart/opencart/pull/142
...替换内容:
- 目录/控制器/common/seo_url.php
- system/library/url.php

重定向精细:
RewriteRule contacto http:....com/index.php?route=information/contact [R=301,L]

重定向不起作用:
重定向 301 contacto http:....com/index.php?route=information/contact

已验证。

Solution Found:
.htaccess redirect 301 working with opencart v1.5.4.1

Additional code needed for... (and credits of this fix):
https://github.com/opencart/opencart/pull/142
... replace contents of:
- catalog/controller/common/seo_url.php
- system/library/url.php

Redirect Fine:
RewriteRule contacto http:....com/index.php?route=information/contact [R=301,L]

Redirect Not Working:
redirect 301 contacto http:....com/index.php?route=information/contact

Verified.

や莫失莫忘 2024-11-07 06:15:26

将其放在路由器前面。还要在 .asp 后面添加 $,在前面添加 ^。

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On

redirect 301 ^contact.asp$ http://www.example.com/index.php?route=information/contact_us
redirect 301 ^downloads.asp$ http://www.example.com/downloads

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

为什么不将联系人重定向到 /information/contact_us 而不是 index.php?route=information/contact_us

Put it in front of router. Also add $ after .asp and ^ in front.

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On

redirect 301 ^contact.asp$ http://www.example.com/index.php?route=information/contact_us
redirect 301 ^downloads.asp$ http://www.example.com/downloads

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

Why don't you redirect contact to /information/contact_us instead of index.php?route=information/contact_us ?

梦太阳 2024-11-07 06:15:26

如果重定向网址末尾不存在像第二个网址那样的 "?" ,您可以尝试在重定向网址末尾添加 "?"

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads?

You can try a "?" at the end of the redirect url if it is not present there like 2nd url(it worked for me) :

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文