Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
RewriteCond %{HTTP_HOST} ^(.*\.)*subexample.example.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://subexample.example.com/$1 [R]   

Is what I have been using. It works as long as I go to a specific page, like subexample.example.com/orders.php. But if you try to go to the root of the subdomain, it adds the extra "/example" at the end.

Any suggestion on a set of rules that will work?


Thank you so much for your responces!

Actually, this is what I am trying to do:

http://support.mydomain.net >> https://support.mydomain.net

AND(!)

http://support.mydomain.net/anypage* >> https://support.mydomain.net/anypage*

> RewriteCond %{HTTPS} off RewriteRule (.*)
> https://%{HTTP_HOST}%{REQUEST_URI}

Works, except I need it to only do it for the support.mydomain.net

With the above set up, you get a certificate warning if you try to go just mydomain.net, which I do not have or need an SSL certificate installed on.

UPDATE!

The other issue with the rule I have written above, is that if you try to go to the root of the subdomain (i.e. support.mydomain.net) it goes to https://support.mydomain.net/support

This is driving me crazy, help! =)

Any help would be greatly appreciated!

share|improve this question

migrated from stackoverflow.com Dec 14 '12 at 9:09

This question came from our site for professional and enthusiast programmers.

1  
Rules that will work for what purpose? It's unclear exactly what you want your rules to do, particularly since you say they aren't doing what you want right now. –  Greg Hewgill Dec 13 '12 at 22:37
    
Hi Zac! Please register your account on Stack Overflow, then come back and log in here. This will associate your account with this question so you can edit it and leave comments again and don't have to resort to posting "answers" as follow up questions. Cheers! –  slhck Dec 14 '12 at 16:31
    
It doesnt look like it associated it with my account...? –  Zac Cleaves Dec 14 '12 at 17:30
    
Oh wait there it goes. Man... this is driving me crazy. If someone can help me fix this I would be most grateful! –  Zac Cleaves Dec 14 '12 at 17:31

1 Answer 1

Based on your code I'm assuming you want to do the following redirections:

http://aaa.subexample.example.com -> https://subexample.example.com/aaa
http://subexample.example.com -> https://subexample.example.com/

And that the latter does not work.

I would rewrite in two different RewriteRule pieces.

RewriteCond %{HTTP_HOST} ^subexample.example.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://subexample.example.com/$1 [L]

RewriteCond %{HTTP_HOST} ^(.+\.)+subexample.example.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://subexample.example.com/$1 [R]
share|improve this answer

Your Answer

 
discard

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.