views:

31

answers:

1

I'm trying to redirect all pages and subdomains by preceeding them with a m. subdomain unless it starts with a m. yet it completely fails. where am I going wrong?

example.com or www.example.com -> m.example.com test.example.com -> m.test.example.com images.example.com -> m.images.example.com m.example.com -> Don't redirect m.test.example.com -> Don't redirect

RewriteCond %{HTTP_HOST} !^m([.].*)?.example.com$

RewriteCond %{HTTP_HOST} ^(.*)?.example.com$

RewriteRule (.*) http://m%2.example.com/$1 [R,L]

+1  A: 

I set up your rules on my test server, but I wasn't able to replicate the recursive redirect. That being said, you should modify it so it looks like the following:

RewriteCond %{HTTP_HOST} !^m([.].*)?\.example\.com$
RewriteCond %{HTTP_HOST} ^(.*)?\.example\.com$
RewriteRule (.*) http://m.%1.example.com/$1 [R,L]

That will at least fix the issue regarding the missing subdomains. (You were missing a dot after the m, and the capture group representing the subdomain is %1)

Since I wasn't able to replicate the other half of the problem though, I'm not sure what might be causing it. If you have any more information you think might help, I'm willing to give it another go though.

Tim Stone