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

Help, please. Can you tell me if this is the correct code to perform the following rewrites? I can't test this particular change like I would like.

This company has four domains in a single apache instance.

I only want to affect one -

I need this block to do the following:

  1. if the host is, any call to / needs to go to /admin/index.php
  2. if the host is, any call to http needs to go to https
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^test\.example\.com
    RewriteRule ^/admin/index\.php$ - [L]

    RewriteCond %{HTTP_HOST} !^test\.example\.com
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /admin/index.php [L]

    RewriteCond %{HTTP_HOST} !^test\.example\.com
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Thanks so much, Lynn


How about something like this?

RewriteCond %{HTTP_HOST} !^test\.lifestylepubs\.com
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}$1
RewriteRule  ^/$ /admin/index.php
share|improve this question

If your apache server serves 4 domains, then I would assume each domain is in its own vhost. If not, that's the first thing I would fix.

Then you can put your rewrite rule in the appropriate vhost configuration and not having to worry about much.

Otherwise your rewrite rules just need:

RewriteCond %{SERVER_NAME}
RewriteRule  ^/$                 /admin/index.php [L]

RewriteCond %{SERVER_NAME}        
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}$1
share|improve this answer
You're not wrong, and I don't disagree. Totally singing to the choir. Unfortunately the bosses dictating my schedule have set the priorities the way they are. I can't take the time right at this moment to do that, although I will asap. Today tho, I need to get test switched over to https. – Lynn Owens Apr 15 '13 at 19:40
I tried that, unfortunately it forced all domains to redirect to HTTPS, and in addition the URL ended up as – Lynn Owens Apr 15 '13 at 19:54
Maybe something like.... (see updated question) – Lynn Owens Apr 15 '13 at 19:58
See edit. I know that works as I use this myself somewhere. – ETL Apr 15 '13 at 21:10

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.