Jun 16, 2012
tom

Multiple mod rewrite condintions via domain / subdomains

Question

I’ve got a site that handles urls on both domain and subdomain.

Here’s the base htaccess:

#redirect products on head domain
RewriteCond %{HTTP_HOST} ^domain.com
#RewriteCond %{REQUEST_URI} ^.+$ [NC]
RewriteRule ^product/([a-z0-90-]+(/*))$ p.php?i=$1 [L]
RewriteRule ^home(/*)$ home.php [L]#redirect products on sub domain
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain.com [NC]
RewriteRule ^home(/*)$ store.php [L]

So basically, first condition sends home to home.php if no subdomain exists and second sends home to store.php, but it’s not doing that.

I’m probably missing something small here, but my brain is fried atm.

Answer

I knew it was something simple… Order counts! Remember the Rule reflects the prior Cond and nothing beyond.

#redirect products on head domain
RewriteCond %{HTTP_HOST} ^domain.com
#RewriteCond %{REQUEST_URI} ^.+$ [NC]
RewriteRule ^home(/*)$ home.php [L]
RewriteRule ^product/([a-z0-90-]+(/*))$ p.php?i=$1 [L]
Answered by Michael Mikhjian

No related posts.

Leave a comment