htaccess 301 使用查询字符串永久重定向

htaccess 301 permanent redirect using query string

我正在尝试使用查询字符串执行 301。

我想重定向

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

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

我已经在 .htaccess 中尝试过:

RewriteEngine on


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

您可以使用此重定向规则:

RewriteEngine on    

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

查询字符串将自动复制到新的 URL。