我有一个旧页面,用于根据查询字符串显示多个产品。我想将带有查询字符串的 url 重写为与旧 url 将被重写到的静态页面不同的静态页面。
RewriteRule ^old.php$ new.php
RewriteRule old.php?product=10 different.php [R=301,L]
在这种情况下,old.php 被重写为 new.php。但是 old.php?product=1O 被重写为 new.php?product=10 而不是 different.php
最佳答案
您无法在重写规则中匹配 QUERY_STRING。您需要使用 RewriteCond %{QUERY_STRING}
来匹配查询字符串。
使用您的规则:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^old\.php$ new.php [L,R]
RewriteCond %{QUERY_STRING} ^product=10$
RewriteRule ^old\.php different.php [L,R]
关于php - .htaccess 用查询字符串重写不同页面的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20656312/