Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How would I get sub.domain.com OR http://sub.domain.com

to do a redirect to https://sub.domain.com

Thanks!

share|improve this question
    
A little more information on your platform would be helpful. –  ScottE Mar 15 '11 at 17:49
    
What programming language? What webserver? –  Tedd Hansen Mar 15 '11 at 17:50
add comment

migrated from stackoverflow.com Mar 16 '11 at 13:40

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

2 Answers

Assuming you are using Apache Web Server, add this to your .htaccess file:

Redirect permanent / https://domain.com/

Then restart apache. Good luck!

share|improve this answer
    
What if i needed just one particular subdomain to do this? like test.domain.com or test.domain.com to redirect to test.domain.com? –  Chris Mar 15 '11 at 17:52
add comment

Assuming you are using Apache and have mod_rewrite you could add the following to your .htaccess file

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule /(.*) https://sub.domain.com [R,L]

This redirects you to https only if you are not using https. If you want this to only apply to certain domains then use:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^test.domain.com$
RewriteRule /(.*) https://sub.domain.com [R,L]
share|improve this answer
add comment

Your Answer

 
discard

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