Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been trying to get an answer to this question on other forums (the folks at SuperUser thought this was the place I needed to post) and via my connections, but I haven't gotten very far. Hopefully you guys can help me find an answer.

I've got a dozen old subdomains that have been indexed by Google. These have been indexed as both HTTP AND HTTPS.

I've managed to redirect all the subdomains properly, provided they are not HTTPS, but can't get any of the HTTPS subdomains to property redirect.

Here's the code I'm using:

RewriteCond %{HTTP_HOST} ^subdomain1.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain2.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain3.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

This works great until someone goes to:

which is not redirected back to http://www.mysite.com$

How can I get this to work? Additionally, I'm guessing there is an easier way to make it happen than setting up a dozen pairs of RewriteCond/RewriteRule? Is there any way to do this in just a few lines, including one where I list all the subdomains?

I'd actually also like to redirect everything on https://www.mysite.com$ to http://www.mysite.com$ except for 3 folders.

These are mysite.com/secure, mysite.com/store, mysite.com/user. Is there any good way to add this to the .htaccess file?

share|improve this question
I'm gust guessing here, but I think you need to match the HTTPS using the following condition. Adapted from askapache.com/htaccess/ssl-example-usage-in-htaccess.html RewriteCond %{HTTPS} =on – skibulk Oct 17 '12 at 23:15
@skibulk Adding that above any of the sets of rewrite conditions that I've already got doesn't do anything for me. Any ideas? Could there be some kind of conflict with another config file? – Joshua Dorkin Oct 18 '12 at 2:48
First of all, should this question belong to stackoverflow? Anyhow stackoverflow.com/questions/1108706/… might help you. – user555 May 5 '13 at 19:11

About not repeating for each subdomain - shouldn't this work?

RewriteCond %{HTTP_HOST} ^.+\.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.