Mod rewrite 基本模块重写困难

Mod rewrite 基本模块重写困难,mod-rewrite,Mod Rewrite,我的目标是重写 http://domain.com/subdir/index.php?p=page-title 作为 下面的代码看起来不错,但是我得到了一个404找不到 RewriteEngine on RewriteRule ^/subdir/([^/.]+)/?$ /subdir/index.php?p=$1 [L] 请从规则中删除前导斜杠(假设它位于.htaccess而不是httpd.conf) 它是否按预期重定向?@revo这是内部重写,不是重定向,所以很难说。也就是说,在标志中使用

我的目标是重写

http://domain.com/subdir/index.php?p=page-title
作为

下面的代码看起来不错,但是我得到了一个404找不到

RewriteEngine on
RewriteRule ^/subdir/([^/.]+)/?$ /subdir/index.php?p=$1 [L]

请从规则中删除前导斜杠(假设它位于
.htaccess
而不是
httpd.conf


它是否按预期重定向?@revo这是内部重写,不是重定向,所以很难说。也就是说,在标志中使用
[R=temp]
通常是查看规则执行情况的一个好方法。@IMSoP但是它有一个隐藏的重定向,我通常使用单词
重定向
来重写规则。@revo在这种情况下,答案是“否”,否则这个问题就不在这里了,当然……我不知道没有
/
为什么它能工作,但是谢谢你的回答。还感谢您提供有用的标志:)@Midas,这是因为.htaccess
RewriteRule
中的路径不是以
/
开头的。
RewriteEngine on
RewriteRule ^/subdir/([^/.]+)/?$ /subdir/index.php?p=$1 [L]
RewriteEngine on
RewriteRule ^subdir/([^/.]+)/?$ /subdir/index.php?p=$1 [NC,QSA,L]