为啥我的 .htaccess 文件的 301 重定向不能正常工作?

Posted

技术标签:

【中文标题】为啥我的 .htaccess 文件的 301 重定向不能正常工作?【英文标题】:Why aren't my 301 redirects with .htaccess file working correctly?为什么我的 .htaccess 文件的 301 重定向不能正常工作? 【发布时间】:2014-11-27 12:57:15 【问题描述】:

我已经安装了带有 SEO Urls 的 Opencart,我已经更改了一些页面的结构,并希望对更改的页面进行 301 重定向,因此不会中断(外部)链接。但是我在 opencart 中激活了 SEO 链接,这意味着激活了一些重写规则,我猜这些会干扰我的 301 重定向代码。

最后一行是我的重定向。不是将http://keroproducts.ch/kaufen 重定向到http://keroproducts.ch/produkte/,而是重定向到:http://keroproducts.ch/produkte/?_route_=kaufen,这是不正确的。

这是我的 .htaccess 文件:

Options +FollowSymlinks

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
 Order deny,allow
 Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 


RewriteCond %HTTP_HOST ^www\.keroproducts\.ch [NC]
RewriteRule ^(.*)$ http://keroproducts.ch/$1 [L,R=301]

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteCond %REQUEST_URI !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]


Redirect 301 /kaufen http://keroproducts.ch/

【问题讨论】:

您正在尝试在打开 RewriteEngine 之前重写。 我已经解决了这个问题。但问题依然存在,请查看更新的代码。 【参考方案1】:

这是解决方案:

http://www.itsadam.co.uk/opencart-301-redirect-not-working-seo-fix-route/

您必须添加一个 ?重定向背后:

Redirect 301 /kaufen http://keroproducts.ch/?

【讨论】:

以上是关于为啥我的 .htaccess 文件的 301 重定向不能正常工作?的主要内容,如果未能解决你的问题,请参考以下文章

301 使用 .htaccess 重定向 URL 模式

.htaccess 结合 301 重定向和 URI 重写

高分请教.htaccess规则写法..URL 301

我如何 .htaccess 301 将所有页面/文件(除了一个)重定向到新域?

为啥这个 301 重定向会导致重定向到错误的 url?

如何使用 .htaccess 正确地将 HTTP 301 重定向到 HTTPS?