4

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

在.htaccess里面

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

但是,对于完美运行的“联系我们”,对于下载 url,它无法正常运行。当我访问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运行 .htaccess (添加了虚拟目录)

对于http://localhost/example

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

对于http://示例

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?路线=下载.asp

著名的

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

但在 Live 版本中,我是直接使用 enter 访问

http://www.example.com/downloads

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

http://www.example.com/downloads?路线=下载.asp

任何的想法?

4

3 回答 3

4

找到的解决方案: .htaccess 重定向 301 与 opencart v1.5.4.1 一起使用

需要的附加代码...(以及此修复的学分): https ://github.com/opencart/opencart/pull/142 ...替换以下内容:-catalog/controller/common/seo_url.php-system/库/url.php

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

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

已验证。

于 2012-10-02T22:12:55.267 回答
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

于 2011-04-08T01:49:51.040 回答
1

你可以试试“?” 如果重定向 url 没有像第二个 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?
于 2013-09-20T11:31:42.803 回答