我刚刚将我的网站从 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/example 和 http://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?
发布评论
评论(3)
找到解决方案:
.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.
将其放在路由器前面。还要在 .asp 后面添加 $,在前面添加 ^。
为什么不将联系人重定向到
/information/contact_us
而不是index.php?route=information/contact_us
?Put it in front of router. Also add $ after .asp and ^ in front.
Why don't you redirect contact to
/information/contact_us
instead ofindex.php?route=information/contact_us
?如果重定向网址末尾不存在像第二个网址那样的 "?" ,您可以尝试在重定向网址末尾添加 "?" :
You can try a "?" at the end of the redirect url if it is not present there like 2nd url(it worked for me) :