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.

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>
    ServerName lvh.me
    ServerAlias *.lvh.me

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

I tried the following, but it did not work.

<VirtualHost *:80>
    ServerName lvh.me
    ServerAlias *.lvh.me

    Redirect temp / https://%{HTTP_HOST}/
</VirtualHost>

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

1 Answer 1

up vote 1 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

 
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.