Redirect non-www to www tenant URL

Topics: Administration, Troubleshooting
Mar 26, 2015 at 1:45 AM
Hi,
I'm trying to use Rewrite module to redirect non-www to www tenant URL (or vice-versa) but in vain. It would be great if someone could please help to understand the correct syntax to use in this module.

Issue:
When trying to access ABC tenant via http://abc.com it works find but when trying to access it like www.abc.com it redirects to default tenant (mysite.cloudapp.net on azure)

Below are the actions I've taken so far:
  1. Added Rewrite module to default tenant
  2. Enabled it on default tenant
  3. Added rewrite rule to redirect non-www URL to www URL
Stuck here:
Now all the request (for default tenant or XYZ tenant - www.xyz.com, xyz.com, mysite.cloudapp.net, abc.com, www.abc.com ) goes to ABC tenant.

Site referred:
http://corz.org/server/tricks/htaccess2.php
Apr 2, 2015 at 8:12 AM
Edited Apr 2, 2015 at 8:12 AM
Firstly ensure each non-default tenant has the www prefixed url as its host (set by editing tenant config via the default tenant's "Tenants" settings).

Then I use this as the rewrite rules in my default tenant's rewrite rules settings...
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9.]+)$ [NC]
RewriteRule ^/(.*)$ http://www.%1/$1 [R=301,L]
Marked as answer by CRawal on 4/19/2016 at 5:39 PM
May 21, 2015 at 2:45 AM
Edited May 21, 2015 at 2:50 AM
Apologies for late reply.. (I know Orchard is moved to GitHub but still wanted to reply in case someone is searching)

Made changes as recommended with a small tweak and it worked like a charm..
Thanks for your response mjy78



RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+.[a-z0-9]+)$ [NC]
RewriteRule ^/(.*)$ http://www.%1/$1 [R=301,L]
Marked as answer by CRawal on 4/19/2016 at 5:39 PM