2014-10-01 134 views
0

在Opencart商店中的.htaccess文件中重定向时出现问题。Opencart 301重定向

似乎任何URL与/index.php?_route_=没有得到重定向。

例如,这个工程:

redirect /old-url-here http://example.com/new-url? 

这不:

redirect /index.php?_route_=some-url.asp http://example.com 

任何想法或建议,以什么可能得到这个工作?

回答

1

您无法使用mod_alias'Redirect指令与查询字符串匹配。你需要使用mod_rewrite,如果你使用mod_rewrite,你可能会想要完全停止使用mod_alias。

尝试:

RewriteEngine On 
RewriteCond %{QUERY_STRING} route=some-url\.asp 
RewriteRule ^index\.php$ http://example.com/ 
0

的另一件事是 - 除了乔恩的答案 - 像index.php?_route_=some-keyword网址是/只创建内部,只有在情况下,你必须在SEO打开。在这种情况下,您点击一个URL为http://yourstore.com/some-keyword的链接,该URL将被重写为index.php?_route_=some-keyword

因此,您不应该自己创建类似的URL,也不要尝试从它们重定向。如果您需要重定向,请抓住第一个SEO网址将其重定向。

我们不知道你在哪里把你变成了.htaccess文件,但如果你在这个重写规则仔细看

RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 

不仅你会发现它的存在最后的规则,但它也有这个交换机告诉Apache服务器,如果这个规则匹配,做一个URL重写(附加查询字符串[QSA]和)停止匹配其他规则[L] - 这是Last one。

如果您需要重定向只是一个特定的URL,这样做同样的方式重定向sitemap.xml的完成(例如),并把它前的最后一个重写规则:

RewriteEngine On 
RewriteBase/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] 
# ... 
# your new rule here - while the URL in the link is http://yourstore.com/some-url.asp 
RewriteRule ^some-url.aspx$ index.php?route=some-folder/some-controller [L] 
# ... 
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]