RewriteMap 在 mod-rewrite 中不起作用
我一直在尝试在 htaccess 中使用 RewriteMap 指令进行简单映射,但由于某种原因我每次都会收到错误 500。我的语法是.. 选项 +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteMap name2id txt:nklist.txt
RewriteRule ^/name/(.*) /name_list_view.php?kid=${name2id:$1|NOTFOUND}
nklist.txt 中的
1 David
2 Mark
3 Simon
: nklist.txt 文件位于我网站的根目录下,与 htaccess 所在的位置相同。据我的调试告诉我 htaccess 无法找到 nklist.txt 文件,但任何帮助将不胜感激。
I have been trying to do simple maping with RewriteMap directive in my htaccess, but for some reason i am getting error 500 everytime. my syntax is ..
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteMap name2id txt:nklist.txt
RewriteRule ^/name/(.*) /name_list_view.php?kid=${name2id:$1|NOTFOUND}
in nklist.txt :
1 David
2 Mark
3 Simon
the nklist.txt file is on the root of my website , same place where the htaccess is . As far as my debugging tells me that htaccess is not able to find the nklist.txt file, but any help would be thankful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的描述,您尝试通过
.htaccess
文件在每个目录上下文中定义RewriteMap
,但这是不允许的。只能定义RewriteMap
在每个服务器上下文中,无论是在主服务器配置中还是在虚拟服务器部分中。当您向服务器发出请求并解析
.htaccess
文件时,它会遇到RewriteMap
指令并发出警报,从而导致抛出 500 错误。您可能会在error_log
中看到一条条目,指出“此处不允许 RewriteMap”。From your description, you're attempting to define a
RewriteMap
in a per-directory context via your.htaccess
file, but this isn't allowed. TheRewriteMap
can only be defined in a per-server context, either in the main server configuration or in a virtual server section.When you make requests to the server and the
.htaccess
file is parsed, it encounters theRewriteMap
directive and issues an alert, which results in an 500 error being thrown. You'll likely see an entry in yourerror_log
that states "RewriteMap not allowed here".