Avatar of qwertq
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.
Apache Web Server

Avatar of undefined
Last Comment
Arty K
SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of qwertq
qwertq

ASKER

will this work for directories too? (directory index)
Avatar of m1tk4
m1tk4
Flag of United States of America image

>>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]
Avatar of qwertq
qwertq

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.
ASKER CERTIFIED SOLUTION
Avatar of m1tk4
m1tk4
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Arty K
Arty K
Flag of Kazakhstan image

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
Apache Web Server
Apache Web Server

The Apache HTTP Server is a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards. Typically Apache is run on a Unix-like operating system, but it is available for a wide variety of operating systems, including Linux, Novell NetWare, Mac OS-X and Windows. Released under the Apache License, Apache is open-source software.

21K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo