Server Fault is a question and answer site for system and network administrators. 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

This Apache reference page and this wiki clearly states that to achieve simple http to https redirects, mod_alias should be used instead of the more expensive mod_rewrite.

I have an Apache virtualhost which uses a wildcard to match multiple subdomains. I need all these subdomains redirected to their corresponding https counterparts. Currently, I am using the following (with mod_rewrite):

<VirtualHost *:80>
    ServerAlias *

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

I tried the following, but it did not work.

<VirtualHost *:80>
    ServerAlias *

    Redirect temp / https://%{HTTP_HOST}/

The apache variable HTTP_HOST doesn't seem to be recognized in redirect directives.

So, is there any other way to use mod_alias to achieve the above effect?

share|improve this question
up vote 2 down vote accepted

You cannot. Redirect is able to handle simple redirections, where you're sending the client to a single, specific name, but does not have the ability to do complex substitutions (setting aside the fact that %{HTTP_HOST} is mod_rewrite-specific).

Just stick with mod_rewrite. mod_alias isn't capable of doing what you need.

share|improve this answer
I suspected that HTTP_HOST is mod-rewrite specific. But I couldn't get any info about it. All I found that HTTP_HOST is an ordinary Apache variable. – Anjan Aug 9 '12 at 9:06

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.