我需要为我的Magento 1商店实现以下重写规则 - 如果查询字符串包含param1
或param2
且URI不是/myfilter/
,则删除它。
以下是一个例子:
www.mystore.com/myfilter/ --> www.mystore.com/myfilter/
www.mystore.com/myfilter/?param1=1 --> www.mystore.com/myfilter/param1=1
www.mystore.com/<something>/?param1=1 --> www.mystore.com/<something>/
www.mystore.com/<something>/?param2=2 --> www.mystore.com/<something>/
我在.htaccess中添加了以下内容:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/myfilter/?
RewriteCond %{QUERY_STRING} param1 [OR]
RewriteCond %{QUERY_STRING} param2
RewriteRule (.*) /$1? [R=301,L]
在标准Magento重定向之前:
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
但它的工作方式错误。 这些网址有效:
www.mystore.com/myfilter/ --> www.mystore.com/myfilter/
www.mystore.com/myfilter/?param3=1 --> www.mystore.com/myfilter/?param3=1
www.mystore.com/<something>/?param1=1 --> www.mystore.com/<something>/
www.mystore.com/<something>/?param2=2 --> www.mystore.com/<something>/
但是当URI包含/myfilter/
以及param1
或param2
时,它会将我重定向到/index.php
:
www.mystore.com/myfilter/?param1=1 --> www.mystore.com/index.php
我错过了什么吗?
答案 0 :(得分:0)
这些规则是我需要的一个技巧:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(index.php/)?myfilter/ [NC]
RewriteCond %{QUERY_STRING} param1 [OR]
RewriteCond %{QUERY_STRING} param2
RewriteRule (.*) /$1? [R=301,L]
RewriteCond %{REQUEST_URI} ^/myfilter/ [NC]
RewriteRule (.*) index.php/myfilter/ [L]