.htaccess redirect without query parameters

2019-08-03 06:58发布

I changed a website and now Google webmaster is loading hundreds of "Not Found" URLs:

http://www.domain.com/images/picture.php?idphotos=720,404,,4/1/13,Not found

The picture.php does not exist anymore so I created a .htaccess entry to redirect the root of the site:

Redirect 301 /images/picture.php. /

Now the problem is that any query parameters are also sent in the redirect:

http://www.domain.com/?idphotos=720

How can I create a redirection which doesn't include the query parameters, e.g. like this:

http://www.domain.com/

2条回答
冷血范
2楼-- · 2019-08-03 07:46

Try this (note the trailing ?):

RewriteCond %{QUERY_STRING} !=""
RewriteRule . http://www.domain.com/?
查看更多
\"骚年 ilove
3楼-- · 2019-08-03 07:48

Alternatively use the QSD flag from Apache 2.4.0

RewriteCond %{QUERY_STRING} !=""    
RewriteRule . http://www.domain.com/ [L,R=301,QSD]

http://httpd.apache.org/docs/current/en/rewrite/flags.html#flag_qsd

查看更多
登录 后发表回答