troubleshooting Question

Rewrite Rule to redirect to

Avatar of tarrigo
tarrigo asked on
Web DevelopmentMicrosoft IIS Web Server
3 Comments1 Solution1174 ViewsLast Modified:
I have tried many different ways of achieving a rewrite that would 301 any request to to and although I can accomplish that, it screws up other subdomains that I don't want to have be affected.

For instance. I have used code like:

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

And that works, but it makes other subdomains that I need to have redirect correctly not work. An example would be: would redirect with above rewrite rule to the following address: 

That I of course don't want. Now the backstory is that I am permanently redirecting users from old subdomains because I no longer want to use subdomains except www. I am now using folders to seperate out sections of the site. I can successfully redirect people as long as I don't have the rewrite rule you see above, but it opens up problems because if I allow a wildcard in the DNS it allows anything to work and I don't want to work or any other such bad urls.

Anybody encountered a similar problem of which they found a solution.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros