简体   繁体   中英

Redirecting in .htaccess

In the htaccess I want to redirect all URL's that end with ?p=X to go to the home page. Here are some examples below which I want to go to the home page but I want to have just 1 statement for all that works:

Redirect 301 "/products/?p=4771" "/"
Redirect 301 "/products/?p=5226" "/"
Redirect 301 "/products/?p=4771" "/"
Redirect 301 "/products/?p=4973" "/"
Redirect 301 "/products/?p=5226" "/"

You can use:

RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)p=\d+(?:&|$) [NC]
RewriteRule ^products/?$    /?  [NC,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