简体   繁体   中英

htaccess redirect with special ? character for php string mod_rewrite in apache

I need to redirect URL's with a keyword string used in our AdWords campaign back to my home page using an htaccess rewrite rule. This is what I have already tried...

RewriteRule ^/?keyword=(.*)$ http://{HTTP_HOST}/$1 [R=301]

example: Looking to make /?keyword=carrots redirect to my home page.

In order to handle redirects involving Query Strings , you will need to use a

RewriteCond %{QUERY_STRING}

in your .htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^$ http://%{HTTP_HOST}/%1/? [NC,L,R=301]

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