我正在尝试将旧网站的旧式链接重定向到php中的新风格链接。
我正在使用:
RewriteEngine on
RewriteBase /
RewriteRule s\.cfm?id=5$ http://mysite.com/article5.php [B,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
但是,如果我只使用 s.cfm?,一切正常并重定向到article5.php。但是,如果我尝试重定向id = 5部分,我会找不到页面。
我尝试了 s.cfm?id ,这会导致htaccess错误。所以你在问号后放了什么?......导致问题,我不知道为什么。
答案 0 :(得分:1)
您无法匹配RewriteRule
内的查询字符串,只有URI路径通过规则本身发送。如果您需要匹配查询字符串,请使用%{QUERY_STRING}
中的RewriteCond
var:
RewriteCond %{QUERY_STRING} ^id=5$
RewriteRule ^/?s\.cfm$ http://mysite.com/article5.php [L,R=301]
其他一切都很好。