Search code examples
regexurl-rewritingsubdomainisapiisapi-rewrite

regex to redirect non www to www and subdomain to file


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


Solution

  • 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