views:

15

answers:

1

Hi All,

I'm trying to do some URL rewriting - but for some reason it's not working as I expected (I've probably missed something really simple!).

I have two sites - www.domain.local and admin.domain.local. Using the below .htaccess file, the public site rewriting is fine, but the admin site isn't working as expected, as it is being picked up by the first condition (even though echoing out the HTTP_HOST shows I'm looking at the admin site domain).

Options -MultiViews
Options +FollowSymLinks

RewriteEngine on
RewriteBase /

## Force www
RewriteCond %{HTTP_HOST} ^domain\.local$ [NC]
RewriteRule ^(.*)$ http://www.domain.local/$1 [R=301,L]

## Public site rewrites   
RewriteCond %{HTTP_HOST} ^www\.domain\.local$ [NC]
RewriteRule ^(home)(/)?$ /index.php [NC]
RewriteRule ^([a-z0-9+-]+)(/)?$ /$1.php [NC,L]

## Admin site
RewriteCond %{HTTP_HOST} ^admin\.domain\.local$ [NC]
RewriteRule ^([a-z0-9+-]+)(/)?$ /manage/$1.php [QSA,L]

What am I doing wrong?

Many thanks, Kev

A: 

A RewriteCond only applies to the next RewriteRule directive, so in your case the admin RewriteRule never gets a chance to execute because this unconditioned rule is applied first:

RewriteRule ^([a-z0-9+-]+)(/)?$ /$1.php [NC,L]

There are a few ways to fix this, but the most straight-forward would be to modify your public site section to include the condition for the second rule:

## Public site rewrites   
RewriteCond %{HTTP_HOST} ^www\.domain\.local$ [NC]
RewriteRule ^(home)(/)?$ /index.php [NC]
RewriteCond %{HTTP_HOST} ^www\.domain\.local$ [NC]
RewriteRule ^([a-z0-9+-]+)(/)?$ /$1.php [NC,L]
Tim Stone
Thanks Tim - I eventually went with this anyway (but thought I was hacking things slightly :) ).
Kevin