mod_rewrite check if file exists

This is a discussion on mod_rewrite check if file exists within the Apache Web Server forums, part of the Web Server and Related Forums category; I've made some mod_rewrite in order to have pretty urls. RewriteEngine on RewriteRule ^/([a-z]+)$ /$1.html [L] How ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-20-2006
Jacob
 
Posts: n/a
Default mod_rewrite check if file exists

I've made some mod_rewrite in order to have pretty urls.

RewriteEngine on
RewriteRule ^/([a-z]+)$ /$1.html [L]

How can I check that the page $1.html exists before I redirect to it?

/Jacob

  #2 (permalink)  
Old 03-20-2006
Robert Ionescu
 
Posts: n/a
Default Re: mod_rewrite check if file exists

Jacob wrote:
> How can I check that the page $1.html exists before I redirect to it?


With a condition

RewriteEngine on
RewriteCond /var/www/$1.html -f
RewriteRule ^/([a-z]+)$ /$1.html [L]

Assuming /var/www is your document root.

--
Robert
  #3 (permalink)  
Old 03-21-2006
Jacob
 
Posts: n/a
Default Re: mod_rewrite check if file exists

Thanks!

Is something like this possible:
RewriteCond $DocumentRoot/$1.html -f

/Jacob

  #4 (permalink)  
Old 03-21-2006
Robert Ionescu
 
Posts: n/a
Default Re: mod_rewrite check if file exists

Jacob wrote:
> Is something like this possible:
> RewriteCond $DocumentRoot/$1.html -f


%{DocumentRoot}, yes, but rely on it only, if you know that it contains
the correct value. E.g. in cases of using ViatualDocumentRoot, the ENV
would be empty. And if you're using the rule only in one virtual host,
you can safe a ENV lookup.

--
Robert
  #5 (permalink)  
Old 03-21-2006
Robert Ionescu
 
Posts: n/a
Default Re: mod_rewrite check if file exists

the ENV is %{DOCUMENT_ROOT}, with an underscore.

--
Robert
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:36 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0