James
James

Reputation: 739

Bypass/exclude a specific set of URLs from a rewriteRule

I'm trying to put a mobile site live on a subdomain. e.g. m.domain.com there is already a desktop site on domain.com.

The domain.com htaccess file has a rewrite rule to redirect all non-www requests to www.domain.com. This is conflicting with the m. subdomain, causing the user to be taken to www.m.domain.com.

Can I add some kind of exclusion to the rewrite rule? Or perhaps specifically overrule the rewriterule?

My non-www to www rewriteRule is as follows:

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Upvotes: 3

Views: 674

Answers (1)

anubhava
anubhava

Reputation: 785256

You can use this rule to avoid impacting m.domain.com from www rule:

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Upvotes: 1

Related Questions