Page 1 of 1

Howto: mod_rewrite directory exclusion

Posted: Tue Jul 04, 2006 1:34 pm
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...

Re: Howto: mod_rewrite directory exclusion

Posted: Tue Sep 12, 2006 11:01 am
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.