How to fwd urls to existing paths AND one more path with apache's mod_rewrite?
My current .htaccess looks like this:
RewriteEngine On # RewriteCond %{REQUEST_URI} !^/_project RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f # RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^.*$ index.php [QSA,L]
The uncommented lines are pretty straightforward:
- The two
Cond
s make sure theRule
isn't applied to existing files (!-f
) and folders (!-d
). - The
Rule
sends everyting else to index.php
The uncommented lines I took from somewhere. I believe it's the best way to do what I require: 'pretty urls'.
Basically it works. Existing files (e.g. /css/general.css
) are requestable and non-existing paths (e.g. /admin/login
) are routed to index.php. Existing and non-existing paths must be able to work 'amongst eachother': /css/all.css
is sometimes a buffered existing css file and sometimes (when it doesn't exist) it's handled by PHP. /css/general.css
is always a file. /css/club_N.css
(N is a number) is always a PHP script.
/_project/
is an existing folder with Basic HTTP Auth protection. For instance /_project/phpinfo.php
works as well. In the _project
folder I have created a (valid) symlink to the backups folder: /_project/backups/
. Somehow the (existing) files in the backups folder can't be reached. For instance /_project/backups/today.bz2
is routed to index.php =( The same happens with either or both commented 开发者_C百科lines uncommented.
What's wrong with the htaccess config? If I remove the Rewrite stuff entirely, I get a 403 Forbidden
. Probably something with the .htaccess
in the _project
folder (?).
PS. Obviously I can't show you the actual website. People wouldn't like it if you could download their backups =)
.htaccess
files are hierarchical in scope, any such files in parent directories apply to their children.
The Basic Auth in /_project/
will apply to subdirectories unless you switch it off in those directories, as will the RewriteRule
declaration. Often it is wise to add RewriteEngine off
in the .htaccess
of the child directory structure to stop the rules applying there, or possibly add a conditional blocking that structure on the original rule set.
精彩评论