【发布时间】:2019-11-21 22:17:28
【问题描述】:
我正在尝试将所有到我网站的流量重定向到单个脚本,如下所示:
example.com/fictitious/path/to/resource
应该变成
example.com/target.php?path=fictitious/path/to/resource
我已经按如下方式设置了我的 .htaccess 文件:
RewriteEngine on
RewriteBase "/"
RewriteRule "^(.*)$" "target.php?path=$1"
target.php 看起来像这样用于测试目的:
<?php echo $_GET["path"] ?>
但是,当我转到“example.com/path/to/resource”时,target.php 只会回显“target.php”而不是“path/to/resource”。当我更改我的 .htaccess 时
[...]
RewriteRule "^([a-zA-Z\/]*)$" "target.php?path=$1"
果然,target.php 忠实地呼应了“path/to/resource”,但只要我在我的规则中添加一个 ESCAPED 点:
[...]
RewriteRule "^([a-zA-Z\/\.]*)$" "target.php?path=$1"
target.php 再次回显“target.php”。
发生了什么事?为什么我的正则表达式中的点会以这种方式与我的捕获组的内容混淆?
【问题讨论】:
标签: regex mod-rewrite apache2