Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

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 to not using VirtualHost defines?

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


share|improve this question
up vote 9 down vote accepted
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
share|improve this answer
RewriteRule ^(.*) https://%{HTTP_HOST}$1 makes more sense to me. – cregox 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. – cregox May 4 '11 at 19:14
I get an infinite loop using Apache 2.4.10, deploying on Heroku, when I insert those commands into my .htaccess. And the variant suggested by Cawas oddly mangles my URL. I've tried a different set of commands: RewriteCond %{HTTP:X-Forwarded-Proto} !https and RewriteRule ^/?(.*) https://%{SERVER_NAME}%{REQUEST_URI} -- which works on Chrome and Firefox, but fails on Safari and Opera. Interestingly, if I take the three lines above and omit RewriteEngine On I no longer get the infinite loop, but it still fails in Safari and Opera (and works in Chrome and Firefox). – Purplejacket Aug 4 '14 at 20:31

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

<Directory /path/to/site>
   Redirect /service 
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.