2011-04-08 150 views
4

我只是将我的网站从asp迁移到opencart。在.htaccess我希望做一些重定向让我的客户可以用回旧的链接访问.htaccess opencart重定向301

内的.htaccess

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 

============ ANOTHER测试========================

我做了一些在我的本地主机上对此进行测试后,我发现这是一个有趣的结果。但是,我的问题仍然没有解决。

我运行。htaccess的从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版本,我没有添加任何重定向代码[非常肯定FOR本]

但在真人版,我访问直接进入

http://www.example.com/downloads

我不知道为什么从本地主机重定向301住版本会出来

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

任何想法?

回答

4

溶液中发现的: htaccess的重定向301 Opencart的v1.5.4.1工作

需要...(和此修复币)附加代码: https://github.com/opencart/opencart/pull/142 ...替换的内容: - 目录/控制器/通用/ seo_url.php - 系统/库/ url.php

重定向精细: 重写规则CONTACTO HTTP:.... COM/index.php的路由信息​​= /接触[R = 301,L]

重定向不工作: 重定向301 CONTACTO HTTP:... COM/index.php的路径=信息/接触

验证。

+0

我替换了'seo_url.php'和'url.php' - 但我需要写入'htaccess'? – 2016-05-02 08:53:33

3

把它放在路由器的前面。在前面加上.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

+0

因为在Opencart的,对这个没办法,你有什么想法解决这个问题。 ? – Shiro 2011-04-08 01:56:07

+0

我改变了你的代码,当我访问http://www.example.com/downloads.asp时,它没有重定向它,它仍然提醒同一个链接http://www.example.com/ – Shiro 2011-04-08 02:02:23

+0

我在我的本地主机上测试了 重定向301 /example/downloads.asp http:// localhost/example/downloads它可以很好地工作,但不能在live版本中运行。 – Shiro 2011-04-08 08:17:26

0

你可以试试“?“在重定向URL结束时,如果它不存在有像第二个URL(它的工作对我来说):

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