简体   繁体   中英

htaccess 301 permanent redirect using query string

I'm trying to do a 301 with a query string.

I want to redirect

www.mydomain.com/page1.php?id=12

To

www.mydomain.com/page2.php?id=12

I've already tried this in .htaccess:

RewriteEngine on


RewriteCond %{QUERY_STRING} ^page_id=([0-9]+)$ 
RewriteRule ^page2.php?page_id=%1 [R=301,L]

You may use this redirect rule:

RewriteEngine on    

RewriteCond %{QUERY_STRING} ^id=\d+$ 
RewriteRule ^page1\.php$ /page2.php [R=301,L,NC]

Query string will be automatically copied over to new URL.

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