Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache Opencart 301重定向_Apache_.htaccess_Mod Rewrite_Redirect_Opencart - Fatal编程技术网

Apache Opencart 301重定向

Apache Opencart 301重定向,apache,.htaccess,mod-rewrite,redirect,opencart,Apache,.htaccess,Mod Rewrite,Redirect,Opencart,Opencart商店的.htaccess文件中存在重定向问题 似乎任何带有/index.php?\u route.=的URL都不会被重定向 例如,这项工作: redirect /old-url-here http://example.com/new-url? 这并不是: redirect /index.php?_route_=some-url.asp http://example.com 有什么想法或建议可以让它工作吗?您不能使用mod_alias'Redirect指令匹配查询字符串。您需要

Opencart商店的
.htaccess
文件中存在重定向问题

似乎任何带有
/index.php?\u route.=
的URL都不会被重定向

例如,这项工作:

redirect /old-url-here http://example.com/new-url?
这并不是:

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

有什么想法或建议可以让它工作吗?

您不能使用mod_alias'
Redirect
指令匹配查询字符串。您需要使用mod_rewrite,如果您使用mod_rewrite,您可能希望完全停止使用mod_别名

尝试:


除了Jon的回答之外,还有一件事是,像
index.php?\u route\u=some关键字
这样的URL只在内部使用/创建,并且只有在您打开SEO的情况下才使用/创建。在这种情况下,您可以单击URL为
http://yourstore.com/some-keyword
此URL将被重写为
index.php?\u route\u=some关键字

因此,您不应该自己创建这样的URL,也不应该尝试从它们重定向。如果需要重定向,请捕获第一个SEO URL以重定向它

我们不知道您在哪里将更改放入了
.htaccess
文件,但如果您仔细查看此重写规则

RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
您不仅会发现这是那里的最后一条规则,而且它还有一个开关,它告诉Apache服务器,如果匹配了此规则,请执行URL重写(,附加查询字符串[
QSA
],并停止匹配其他规则[
L
])——这是最后一条规则

如果只需要重定向特定的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]
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]