简体   繁体   中英

htaccess 301 redirect urls with question mark

I noticed that there are many links reported in Google Search Console that have a question mark after at the root of the domain (index.php.)

This happened because I had redirected an old domain to my new one. I want to use htaccess to 301 ONLY pages that have a question mark at the root level.

For example:

?name=TheFoolOnTheHill
?name=PennyLane

would both redirect to the root level of the domain.

But it would NOT effect other urls such as:

/songs/?name=TheFoolOnTheHill
/songs/?name=PennyLane

I would appreciate any help on how to accomplish this.

You can use Rewrite for this. Give this a try for any url with a query string at the root level.

RewriteEngine on
RewriteCond %{QUERY_STRING} .
RewriteRule ^$ /? [R=301,L]

URL like this

http://example.com/?name=123

Will redirect to root.

This is possible to solve with your .htaccess file.

Redirect 301 ?name=TheFoolOnTheHill /
Redirect 301 ?name=PennyLane /

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