[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mod_rewrite: only effect files that do not exist

Posted on 2006-05-09
6
Medium Priority
?
275 Views
Last Modified: 2010-03-04
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.
0
Comment
Question by:qwertq
6 Comments
 
LVL 27

Assisted Solution

by:caterham_www
caterham_www earned 300 total points
ID: 16643118
Yes, e.g.

RewriteEngine on
# does not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /something [L]
0
 

Author Comment

by:qwertq
ID: 16643242
will this work for directories too? (directory index)
0
 
LVL 15

Expert Comment

by:m1tk4
ID: 16644380
>>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]
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:qwertq
ID: 16644822
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.
0
 
LVL 15

Accepted Solution

by:
m1tk4 earned 300 total points
ID: 16645105
RewriteCond %{REQUEST_FILENAME} !-f    : means "if requested file name is not a file"
RewriteCond %{REQUEST_FILENAME} !-d   : means "and if requested filename is not a directory"
RewriteCond %{REQUEST_FILENAME} !-l    : means "and if requested filename is not a symlink"
RewriteRule ^ /something [L]                    : means "then replace anything (^) with /something and stop ([L])
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16665005
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
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question