Forum Moderators: phranque

Message Too Old, No Replies

Rewrite all directories and subs, except three

         

pblancher

6:17 am on Mar 1, 2007 (gmt 0)

10+ Year Member



This is the existing code:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^./]+)/?$ /viewpage.php?level_one=$1&level_two=$2&level_three=$3&level_four=$4 [L]
RewriteRule ^([^/]+)/([^/]+)/([^./]+)/?$ /viewpage.php?level_one=$1&level_two=$2&level_three=$3 [L]
RewriteRule ^([^/]+)/([^./]+)/?$ /viewpage.php?level_one=$1&level_two=$2 [L]
RewriteRule ^([^./]+)/?$ /viewpage.php?level_one=$1 [L]
ErrorDocument 404 [site.net...]

What I want to do is exclude the following directories:

/admin
/images
/includes

How do I do this?

jdMorgan

2:22 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The easiest way is add another rule ahead of those rules that does one of two things; Either skips the following four rules or terminates mod_rewrite processing altogether if one of your excluded directories is requested.

The alternative is to add a RewriteCond to each of your existing four rules to prevent each one from being applied when requests for the excluded directories are received.

As an example.of the first option, you could add:


RewriteRule ^(admin¦images¦includes)/ - [S=4]

to skip over the following four rules if any of those subdirectory paths is requested. Alternately, change "[S=4]" to "[L]" if you have no need to process any subsequent rules for requests to those subdirectories.

Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim