我正在尝试重定向大量 404。
一些旧网站链接到
http://example.com/product.tmpl?SKU=XXX
其中 XXX
是 SKU 数字。
我希望它重定向到
http://example.com/product.php?SKU=XXX
这是我已经到达的地方,但它仍然不起作用。我的代码有错字吗?
RewriteEngine On
RewriteCond %{QUERY_STRING} ^SKU=([^&]+)
RewriteRule ^/?product\.tmpl$ /product.php?SKU=%1 [L,R=301]
编辑:我的完整 htaccess 文件如下:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^SKU=([^&]+)
RewriteRule ^/?product\.tmpl$ /product.php?SKU=%1 [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
最佳答案
尝试一下:
RewriteRule ^/?product\.tmpl$ /product.php [L,QSA]
修饰符 QSA 保留查询字符串,无论它是什么:http://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_qsa
关于.htaccess - htaccess 重定向并保留变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32705740/