Here is what I have got:

  • CentOS 5.4 (32-bit)
  • installed Apache httpd (Server version: Apache/2.2.11 (Unix))
  • mod_rewrite already presents

Question: how to redirect simple http://site.com to https://site.com not using VirtualHost defines?

PS: tried to find in later answers on SF, but doesn't find nice solution.

Thanks.

link|improve this question
feedback

2 Answers

up vote 7 down vote accepted
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
link|improve this answer
1  
RewriteRule ^(.*) https://%{HTTP_HOST}$1 makes more sense to me. – Cawas May 3 '11 at 15:40
Won't that infinite loop on you? – Ernest Mueller May 4 '11 at 4:14
Nope, just tested it. It's even how it's advised under the docs - look at the end of it. – Cawas May 4 '11 at 19:14
feedback

You can use mod_alias and Redirect based on directory. The linked document identifies additional details.

<Directory /path/to/site>
   Redirect /service https://foo2.example.com/service 
</Directory>
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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