qwertq
asked on
mod_rewrite: only effect files that do not exist
is there a way to have a mod_rewrite which will check if the file exists and if it does not do anything? otherwise go to a specified php page.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>will this work for directories too? (directory index)
No. A complete solution that would work on directories and symlinks would be:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ /something [L]
No. A complete solution that would work on directories and symlinks would be:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ /something [L]
ASKER
can you explain to me what this is:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
let me tell you what i have now, and trying to improve.
RewriteRule ^[^\.]+$ pageHandler.php
basically i am sending any request which does not have a . in it to the php page. this presumes that anything with a . would be referencing a real file on the server. this works great, except that i can not then display directory indexs. so i guess i want to see if the FOLDER, not FILE (sorry) exists on the server and if ti does then go to it, else to go the php which by the file name i am sure you can tell manages all the page requests for the site.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
let me tell you what i have now, and trying to improve.
RewriteRule ^[^\.]+$ pageHandler.php
basically i am sending any request which does not have a . in it to the php page. this presumes that anything with a . would be referencing a real file on the server. this works great, except that i can not then display directory indexs. so i guess i want to see if the FOLDER, not FILE (sorry) exists on the server and if ti does then go to it, else to go the php which by the file name i am sure you can tell manages all the page requests for the site.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
qwertq, your task is better to be done with ErrorDocument directive, not with mod_rewrite, read http://httpd.apache.org/docs/1.3/mod/core.html#errordocument
Error 404 is generated when file is not found, use something like this:
ErrorDocument 404 /default/index.html
Error 404 is generated when file is not found, use something like this:
ErrorDocument 404 /default/index.html
ASKER