Htaccess 帮助,$1 在设置之前被使用???什么?
我有这个片段
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|img|css|js|robots\.txt)
RewriteRule (.*) index.php?/$1 [L]
它不允许我访问 website.com/js/main.php 上的文件 但它会让我访问index.php
根据我的网络主机,$1 在设置之前被调用。有什么解决办法吗?
明天回来时我会接受答案。谢谢你!
I have this snippet
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|img|css|js|robots\.txt)
RewriteRule (.*) index.php?/$1 [L]
It won't allow me to access a file at website.com/js/main.php
but it will let me access index.php
According to my webhost, $1 is being called before it is set. Any solutions?
I'll accept answers when i get back tomorrow. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您希望重写忽略您的条件当前指定的内容。在这种情况下...
...应该可以正常工作。您可能希望那里有 QSA,以便在有查询字符串时能够得到正确处理。
I'm assuming you want the rewrite to ignore the things which your condition currently specifies. In that case...
...should work fine. You'll probably want the QSA on there so that if there's a query string, it's properly handled.
您的虚拟主机错误。 规则集处理顺序是:
中的模式测试 RewriteRule
(将用值填充$N
引用)关联的
RewriteCond
条件(如果存在)仅当模式与当前 URL 路径匹配时 并且满足关联条件时,将应用该模式。因此,在您的情况下,模式
(.*)
在当前 URL 路径js/main.php
上进行测试(没有本地前缀/
)。它匹配 ($0
=js/main.php
,$1
=js/main.php
),所以这三个关联条件按照出现的顺序进行测试:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\ .php|images|img|css|js|robots\.txt)
假设请求的 URL 路径
/js/main.php
不是引用现有的文件或目录,则第一个条件都为真。但第三个将评估为 false,如$1
=js/main.php
和模式^(index\.php|images|img|css|js |robots\.txt)
匹配 (^js
分支)js/main.php
。因此,条件未满足,规则未应用。Your web host is wrong. The order of ruleset processing is:
RewriteRule
is tested (that will populate the$N
references with values)RewriteCond
conditions are tested (if present)Only if the pattern matches the current URL path and the associated condition is fulfilled, the pattern is applied.
So in your case the pattern
(.*)
is tested on the current URL pathjs/main.php
(without local prefix/
). It matches ($0
=js/main.php
,$1
=js/main.php
) so the three associated conditions are tested in the order they appear:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|img|css|js|robots\.txt)
Assuming that the requested URL path
/js/main.php
does not refer to an existing file or directory, the first conditions are both true. But the third one will evaluate to false as$1
=js/main.php
and the pattern^(index\.php|images|img|css|js|robots\.txt)
matches (^js
branch)js/main.php
. So the condition is not fulfilled and the rule is not applied.