magento:某些 htaccess 重定向不起作用

Posted

技术标签:

【中文标题】magento:某些 htaccess 重定向不起作用【英文标题】:magento : some htaccess redirection doesn't work 【发布时间】:2015-10-02 00:31:10 【问题描述】:

使用 magento 1.7 FR,我在 htaccess 中有一些重定向规则,但并非所有规则都有效,我找不到原因:

Options +FollowSymLinks
RewriteEngine on

# This is working
Redirect 301 /blog/conseils-literie/literie-et-matelas-pirelli.html http://example.com/produits/literie.html
Redirect permanent /catalogues/ http://example.com/

# This is not working !
Redirect 301 /produits.html?marque=32 http://example.com/32/bultex.html
# I replaced it with this but no way !
RewriteCond %HTTP_HOST ^example.com/produits.html?marque=32
RewriteRule ^(.*)$ http://example.com/32/bultex.html$1 [R=301,L]

我确定后端没有设置 URL 重定向!

【问题讨论】:

这是您的整个 .htaccess 文件吗?你确定你没有重写或重定向规则,例如 httpd.conf 文件? 我找到了这个模拟器:htaccess.madewithlove.be。我厌倦了这些规则: RewriteCond %QUERY_STRING ^marque=32$ \n RewriteRule ^produits.html /32/bultex.html [NC,R,L] ...模拟器说没关系,但规则不起作用在真实服务器中!! 添加了一个赏金,希望能引起足够的注意力到你得到答案的线程上。请尝试您获得的示例,并接受有效的答案。 【参考方案1】:

这在我的服务器上运行良好:

RewriteCond %THE_REQUEST /produits\.html\?marque=([^&\s]+) [NC]
RewriteRule ^ /%1/bultex.html? [NE,NC,R,L]

删除或注释掉 .htaccess 中的重定向行并将此规则放在那里。不要从目标 url 的末尾删除 ? 否则查询字符串 "?marque=32" 将被附加到它并且 url 看起来像:

/32/bultex.html?marque=32

【讨论】:

以上是关于magento:某些 htaccess 重定向不起作用的主要内容,如果未能解决你的问题,请参考以下文章

为啥这个 .htaccess 重定向不起作用?

为啥我的 .htaccess 301 重定向规则不起作用?

.htaccess 重定向但排除某些文件夹

htaccess 301 重定向某些 URL 模式

apache 2.4中的htaccess重定向301不起作用

htaccess url重定向参数不起作用