简体   繁体   中英

Removing query string from 301 redirect via htaccess

I want to redirect URLs like these:

http://domain1.com/video.php?id=248
domain1.com/details.php?id=4028

to

http://domain2.com/

But I'm getting the redirects as:

http://domain2.com/?id=248
http://domain2.com/?id=4028

Using the following code in my .htaccess

RewriteEngine On
RewriteRule .* http://domain2.com/ [R=301,L]

I've experimented with %{QUERY_STRING} but I get no redirect. I don't know what I'm doing. Someone please help me!

You need to add a ? to the end of the target to create a new (blank) query string. By default, mod_rewrite will append any existing query string unless one is explicitly created by the rule (in which case a QSA flag is needed to append it):

RewriteEngine On
RewriteRule .* http://domain2.com/? [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM