Htaccess 301在查询结束时重定向附加变量

时间:2013-02-22 11:19:12

标签: .htaccess redirect

我正在尝试将一些现有的mod_rewrite查询重定向到更好的对应方,但遇到了将页面的变量附加到URL末尾的问题。

例如,

/garden/garden-benches/cat_199.html 

正在变成:

/garden-furniture/patio-furniture/garden-benches-garden-seats/cat_199.html?_a=viewCat&catId=199

我最后不想要那些变量。

代码是:

RewriteEngine On
Redirect 301 /garden/garden-benches/cat_199.html http://www.sustainable-furniture.co.uk   /garden-furniture/patio-furniture/garden-benches-garden-seats/cat_199.html

.htaccess文件的其余部分 - 首先创建网址。

RewriteBase /
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule cat_([0-9]+)(\.[a-z]{3,4})?(.*)$    index.php?_a=viewCat&catId=$1&%1 [NC]

RewriteCond %{QUERY_STRING} (.*)$
RewriteRule prod_([0-9]+)(\.[a-z]{3,4})?$   index.php?_a=viewProd&productId=$1&%1 [NC]

RewriteCond %{QUERY_STRING} (.*)$
RewriteRule info_([0-9]+)(\.[a-z]{3,4})?$   index.php?_a=viewDoc&docId=$1&%1 [NC]

RewriteCond %{QUERY_STRING} (.*)$
RewriteRule tell_([0-9]+)(\.[a-z]{3,4})?$   index.php?_a=tellafriend&productId=$1&%1 [NC]

RewriteCond %{QUERY_STRING} (.*)$
RewriteRule _saleItems(\.[a-z]+)?(\?.*)?$   index.php?_a=viewCat&catId=saleItems&%1 [NC,L]

1 个答案:

答案 0 :(得分:0)

重写和重定向是两回事。但是,您仍然可以通过标记规则来重定向:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^garden/garden-benches/cat_199\.html$ garden-furniture/patio-furniture/garden-benches-garden-seats/cat_199.html [R=301,L]

修改1 - 我删除了RewriteCond %{REQUEST_FILENAME} !-f条件。也许它会跳过它,因为.html文件是文件,并且不会通过规则进行过滤。