[英].htaccess 403 Forbidden if url contains directory with another htaccess file
我在网站根目录中有一个.htaccess
文件,它具有以下规则:
Options -MultiViews
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA]
子目录中的另一个.htaccess
文件(我们称其为Foo
):
Order Allow,Deny
Deny from all
<files ~ "\.(js|jpe?g|png|gif|bmp|css)">
Allow from all
</files>
例如,当我访问/test/test/test
它通常将我重定向到index.php
,但是当我的URI以现有目录开头时,它将引发403错误,例如: /Foo/test/test/test
=> 403错误
所以我的问题是: 即使与现有子目录匹配,如何使其重定向到index.php
?
注意:Sub-Directoy必须包含.htaccess文件,以禁止直接访问其中的文件。
另一个问题: 如何发出除(图像,css,js)之外的所有请求(甚至是现有文件和目录)去index.php?url=$1
? 当我删除RewriteCond %{REQUEST_FILENAME} !-f
它将重定向到index.php?url=index.php&url=$1
或给出Internal Error
保持根.htaccess如下:
Options All -Indexes -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(.*)$ [NC]
RewriteCond %{REQUEST_URI} !(^/index\.php|\.(js|jpe?g|png|gif|bmp|css))$ [NC]
RewriteRule ^ /index.php?url=%1 [QSA,L]
保持您的/Foo/.htaccess
如下:
RewriteEngine On
RewriteOptions Inherit
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule !\.(js|jpe?g|png|gif|bmp|css)$ - [F,NC]
RewriteOptions Inherit
将从父.htaccess继承规则 mod_rewrite
进行更好的控制,而不是allow/deny
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.