0

I need to do the following .. have come across various examples but i need to combine three conditions

redirect 1) redirect non www / non subdomain requests. eg :

http://xyzsite.com to http://www.xyzsite.com

2) redirect if subdomain is mentioned . eg :

http://user1.xyzsite.com to http://www.xyzsite.com/profile?user1

3) redirect to mobile version. eg :

http://m.xyzsite.com to http://www.xyzsite.com/m

Tech details : I m on IIS ver 6 & using helicontech isapi_rewrite module

suraj jain
  • 1,012
  • 14
  • 26

3 Answers3

0

Here are the ISAPI_Rewrite v3 rules (hope this is the version you use):

RewriteBase /
RewriteCond %{HTTP_HOST} ^xyzsite\.com$
RewriteRule .? http://www.xyzsite.com [NC,R=301,L]

RewriteCond %{HTTP_HOST} ^m\.xyzsite\.com$
RewriteRule .? http://www.xyzsite.com/m [NC,R=301,L]

RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.xyzsite\.com$
RewriteRule .? http://www.xyzsite.com/profile?%1 [NC,R=301,L]
TonyCool
  • 1,004
  • 1
  • 6
  • 5
0

1.

  • Match: ^xyzsite.com$
  • Redirect: www.xyzsite.com

2.

  • Match: ^(?!www.)(.*).xyzsite.com$
  • Redirect: www.xyzsite.com/profile?$1

3.

  • Match: ^m.(.*)$
  • Redirect: www.$1/m
Bohemian
  • 412,405
  • 93
  • 575
  • 722
-1

I spent some time on this to hopefuly get you in the right direction. I come up with easiest solution unless you specified a constraint expliciterly. This means that I hardcode xyzsite.com in the regex. This actualy higlight the essense more of the solution

1) redirect non www / non subdomain requests. eg : http://xyzsite.com to http://www.xyzsite.com

pattern:
http://(.*?.com)

replacement:
http://www.$1

2) redirect if subdomain is mentioned . eg : http://user1.xyzsite.com to http://www.xyzsite.com/profile?user1

pattern:
(http://)(.*?)\.(.*)

replacement:
$1www.$3/profile?$2

3) redirect to mobile version. eg : http://m.xyzsite.com to http://www.xyzsite.com/m

pattern:
http://m\.(.*)

replacement:
http://www.$1/m

Hope this helps, Buckley

buckley
  • 13,690
  • 3
  • 53
  • 61
  • your answer to 1) will redirect `http://www.xyzsite.com` to `http://www.www.xyzsite.com`, and then to `http://www.www.www.xyzsite.com` in an infinite redirect loop – Bohemian Mar 21 '12 at 08:44