且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

url 变量的 htaccess 301 重定向问题

更新时间:2023-10-21 13:14:04

您不能将查询字符串参数放在 Redirect 指令的源 URI 路径中.为此,您必须使用 mod_rewrite 的 %{QUERY_STRING} 变量:

You can't put query string parameters in the source URI path of the Redirect directive. You'll have to use mod_rewrite's %{QUERY_STRING} variable for that:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^/?product.php$ http://website.com.au/product_123.php? [L,R=301]

或者使其更通用:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([^&]+)
RewriteRule ^/?product.php$ http://website.com.au/product_%1.php? [L,R=301]