I have the following directory structure in htdocs:
htdocs/
.htaccess
index.php
foo/
bar/
priv/
I'm trying to achieve clean URLs and basically want everything routed through index.php
. My .htaccess
file is as follows:开发者_开发百科
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f # <- referring to this next
RewriteRule .* index.php [L]
This works well in the sense that I can access legitimate files inside of foo/
and bar/
directly, however I'm also able to access files in priv/
which is what I want to disallow. How do I modify the above referenced line to basically say: "disable for files that are NOT in priv/
"?
EDIT: I'm trying to avoid having to do "priv/.htaccess
" -> "deny from all
", and instead would like to process this in index.php
like any other "pretty url" conversion.
You can add another RewriteCond
with the condition just to match ^priv/
and combine it with OR:
RewriteCond $0 ^priv/ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
Now this rule is applied if either the matched partial path starts with priv/
or if the request cannot be mapped onto an existing file.
精彩评论