开发者

mod_rewrite - failing on HTTP host condition

I'm try开发者_如何学Going 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 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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜