Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite working under sub directories

how to make some sub directories exempt from mod_rewrite

         

wfernley

9:46 pm on Mar 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I am having a problem I have this in my httpd.conf file:

<Directory />
Options FollowSymLinks
AllowOverride None
RewriteEngine On

RewriteRule ^(.*)\.html$ $1.php
</Directory>

I have a sub directory that has an actual .html file. When I try to pull up this .html file it will use the mod_rewrite rule and look for a php file. How do I turn it off for this sub directory?

Thanks in advance for your help :)

Wes

jdMorgan

10:00 pm on Mar 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a RewriteCond to block the rule for that specific file, or to check for file exist before rewriting:

# Execute rule only if requested URL is not the specific .html file
RewriteCond %{REQUEST_URI} !^/URL_path_to_specific/file\.html$

-or-

# Execute rule only if requested filename does not exist
RewriteCond %{REQUEST_FILENAME} !-f

One or the other of those may be more suited to your situation.

Jim

wfernley

2:09 pm on Mar 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks JdMorgan.

It doesn't seem to work.

This is my mod_rewrite info in my httpd.conf file:

<Directory />
Options FollowSymLinks
AllowOverride None
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f

RewriteRule /(.*)/(.*)/(.*)/(.*)/index\.html listing.php?input=$4
RewriteRule /(.*)/(.*)/(.*)/index\.html listing.php?input=$3
RewriteRule /(.*)/(.*)/index\.html listing.php?input=$2
RewriteRule /(.*)/index\.html listing.php?input=$1
RewriteRule ^(.*)\.html$ $1.php
</Directory>

Now one other thing I noticed when search google is that I should stay away from *'s is this true? If so I would have to change it to ([0-9A-Za-z]+) correct?

Thanks again for your help.

Wes

jdMorgan

2:16 pm on Mar 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd recommend using the pattern "([^/]+)" in this case -- "match one or more characters not equal to a slash," or put another way, "match all characters up to the next slash." This is much more efficient than "(.*)" because it avoids recursive evaluation of the string.

Jim

wfernley

2:36 pm on Mar 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alright, I will have to try that :)

What about the problem with the .html files.

Is there anyway I can exclude that sub direcotry all together?