Howto: mod_rewrite directory exclusion

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
User avatar
chilsta
Forum Members
Forum Members
Posts: 52
Joined: Thu Oct 20, 2005 8:22 pm

Howto: mod_rewrite directory exclusion

Post by chilsta »

(Posting this here for future reference and in case it helps anyone else).

My shared host has a standard redirect for all domains to /stats

Unfortunately the standard mod_rewrite rules in the CMSMS .htaccess file conflicted with this and trying to view /stats took me to the CMS' 404 page.

To fix this I added 3 lines to .htaccess like this:
Before:

Code: Select all

RewriteEngine On
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.+)\.html$ /index.php?page=$1 [QSA]
After:

Code: Select all

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/failed_auth.html$
RewriteRule ^.*$ - [L]
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.+)\.html$ /index.php?page=$1 [QSA]
This is for Dreamhost, I think other shared hosts may need different solutions, but if you have the same problem, this'd be worth a try. See Dreamhost's mod_rewrite wiki page for more info.

Cheers,

C*

P.S. I should probably put the phrase pretty URLs in here too in case someone's searching by that...
Last edited by chilsta on Wed Jul 05, 2006 5:33 pm, edited 1 time in total.
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm

Re: Howto: mod_rewrite directory exclusion

Post by scooper »

I had a similar problem which only meant I got the CMSMS 404 page when I password protected a directory outside CMSMS using .htaccess

The above code didn't quite work for me (not on Dreamhost), but something close did... annoyingly though I can't quite work out why.

Anyway - for what it's worth, I had to change the start of line char (^) to an exclamation mark (!) so from:

Code: Select all

RewriteCond %{REQUEST_URI} ^/directoryToIgnore/(.*)$ 
RewriteRule ^.*$ - [L]
to

Code: Select all

RewriteCond %{REQUEST_URI} !/directoryToIgnore/(.*)$ 
RewriteRule ^.*$ - [L]
I'm staring at the manul for RewriteCond and can't for the life of me work out why I need to negate the expression - but, natch, it works and so I'll add to this thread in case anyone else has this problem (or anyone wants to tell me why it works...).

s.
Locked

Return to “Tips and Tricks”