问题描述
我在网站根目录下的的.htaccess
文件下列规则:
I have a .htaccess
file in website root with the following rules :
Options -MultiViews
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA]
而在一个子目录另一个的.htaccess
文件(姑且称之为富
):
And another .htaccess
file in a sub-directory (let's call it Foo
) :
Order Allow,Deny
Deny from all
<files ~ "\.(js|jpe?g|png|gif|bmp|css)">
Allow from all
</files>
当我访问,例如: /检验/检验/试验
它通常重定向我的index.php
,但是当我在我的URI开始与现有的目录,它抛出403错误,例如: /美孚/检验/检验/试验
=> 403错误
When I access for example : /test/test/test
it normally redirects me to index.php
, but when I my URI starts with existing directory it throws 403 error, ex : /Foo/test/test/test
=> 403 Error
所以我的问题是:如何使它重定向到的index.php
,即使它匹配现有的子目录
So my question is : How to make it to redirect to index.php
even if it matches an existing sub-directory?
注:子Directoy必须包含一个.htaccess文件来禁止它直接访问文件的
另一个问题:如何使所有的请求(即使是现有的文件和目录)除(图片,CSS,JS)去的index.php URL = $ 1 $ C $? C>
:当我删除的RewriteCond%{} REQUEST_FILENAME -f
重定向到的index.php URL =的index.php和放?!?; URL = $ 1
或给内部错误
Another Question : How to make all requests (even existing files and directories) except (images, css, js) to go to index.php?url=$1
? When i remove RewriteCond %{REQUEST_FILENAME} !-f
it redirects to index.php?url=index.php&url=$1
or gives Internal Error
推荐答案
请您根的.htaccess,如下:
Keep your root .htaccess as this:
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继承
将继承父的.htaccess 规则 - 而不是
/中允许拒绝
更好地使用的mod_rewrite
为更好地控制这里 RewriteOptions Inherit
will inherit rules from parent .htaccess- Instead of
allow/deny
better to usemod_rewrite
for finer control here
这篇关于的.htaccess 403禁止如果URL中包含的目录与另一htaccess文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!