Apply rule to all domains

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 1
Joined: 06 Mar 2013, 17:04

Apply rule to all domains

06 Mar 2013, 17:13

I need to remove the "www." from all domains. This code works fine for an individual domain:

Code: Select all
RewriteCond %{HTTP:Host} ^www\.subdomain\.domain\.edu$ [NC]
RewriteRule .? http://subdomain.domain.edu$1 [R=301,L]


Is there a way to rewrite this so it applies to all domains? I want to do something like this:
Code: Select all
RewriteCond %{HTTP:Host} ^www\.(.+)$ [NC]
RewriteRule .? http://$1$2 [R=301,L]


... but the $1 wont reference the (.+) in the rewritecond.

I have 20 domains and I would rather not run a separate rule for each one when they all do the same thing!

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Apply rule to all domains

06 Mar 2013, 22:52

Hello,

Lets try using the following rule:
Code: Select all
RewriteCond %{HTTP:Host} ^www\.([^.]+\.[^.]+\.[^.]+)$ [NC]
RewriteCond %{REQUEST_URI} (.*)
RewriteRule .? http://%1%2 [R=301,L]


This rule is supposed to cover domains that start with "www" and are followed by three parts separated by '.'

So it will match both "www.subdomain.domain.com" and "www.domain.com.au", so you'd need to do corresponding adjustments suitable for your domain system.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 4 guests