简体   繁体   中英

Apache RewriteRule for querystring

I need to rewrite URL with querystring:

http://www.example.com/?p=121&cpage=7

to:

http://www.example.com/

What's the easiest way to do it on .htaccess?

You can achieve that using:

RewriteEngine On
RewriteCond %{QUERY_STRING} p=(.+)$ 
RewriteRule ^(.*)$ http://www.example.com? [R=301,L]

The {QUERY_STRING} will detect the correct query, and if the condition is met it will rewrite it to www.example.com .

The ? at the end of the redirected URL is there so that the query string does not appear on the end of the URL.

Make sure you clear your cache before testing this.

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