[英]Any character match not working in Apache mod_rewrite RewriteRule
我正在尝试使用Apache的mod_rewrite
重写网站上的URL。
我在.htaccess
文件中包含以下行,该文件位于服务器根目录中的foo
文件夹中:
RewriteEngine On
RewriteBase /foo/
RewriteRule ^(.+)$ index.php?id=$1 [NC,L]
这个想法是提取URL http://abc.example.com/foo/bar
foo/
之后的所有内容,并将其重写为http://abc.example.com/foo/index.php?id=bar
,我认为应该很简单-这不是我第一次使用mod_rewrite
。
我已经在http://htaccess.madewithlove.be上成功进行了测试,但是,我发现在服务器上,只有在我使用[az]+
而不是规则中的通配符.+
,它才能正常工作。 否则, id
参数返回index.php
。
我的规则声明有问题吗? 如果不是,什么配置可能导致这种行为,我该如何覆盖呢?
值得一试,以防其他重写,或者偶然地将您重写到index.php:
RewriteRule ^(?!index.php)(.*) index.php?id=$1 [NC,L]
尝试这个,
RewriteEngine On
RewriteBase /foo/
RewriteRule ^(.+)$ index.php?id=$1 [QSA,NC,L]
问题可能与查询字符串有关。
https://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.