Reputation: 5792
I have .htaccess file like:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^/?market/(.*)$ http://market.example.com/$1 [L,R=301]
RewriteRule ^/?buddies/(.*)$ http://buddies.example.com/$1 [L,R=301]
RewriteRule ^/?bazaar/(.*)$ http://bazaar.example.com/$1 [L,R=301]
It works fine in market subdirectory. It redirects to the subdomain. But, There is a problem with other 2 subdirectories.
ERROR FOR OTHER 2 sub-domains:
The page isn't redirecting properly
What should I do to overcome this problem?
Upvotes: 3
Views: 3478
Reputation: 786289
It is because RewriteCond
is only applicable to the very next RewriteRule
. Your last 2 rules execute for all the hosts including buddies
and bazaar
and causes redirection loop.
You need these rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^/?market/(.*)$ http://market.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^/?buddies/(.*)$ http://buddies.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^/?bazaar/(.*)$ http://bazaar.example.com/$1 [L,R=301]
Upvotes: 5