Options +FollowSymLinks
RewriteEngine On
RewriteMap name2id txt:/path/to/map.txt
RewriteRule ^/mods/([^/]+)\.html$ /mod.php?id=${name2id:$1|0} [QSA,L]
第一次使用rewriteMap进行URL重写 . 我上面有一个代码,但如果我在浏览器中运行 http://example.com/mysite/mods/abc.html
,它会返回404页面 . 我已将上述代码放在我的虚拟主机文件中的apache配置中,我在一些论坛中读到,只有在httpd.conf和虚拟主机中有访问权限时,rewriteMap才有效 . mod_rewrite正在我的Windows机器上运行,因为我能够运行我的.htaccess文件中定义的一些规则 .
map.txt包含
abc 123
def 456
ghi 789
2 回答
如果您请求
/mysite/mods/…
,您的规则应该是:如果您正在使用RewriteBase,请尝试删除规则中的初始斜杠: