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.

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 - test.example.com.

I need this block to do the following:

  1. if the host is test.example.com, any call to / needs to go to /admin/index.php
  2. if the host is test.example.com, 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

UPDATE:

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

1 Answer 1

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}       =test.example.com
RewriteRule  ^/$                 /admin/index.php [L]

RewriteCond %{SERVER_NAME}       =test.example.com        
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 prod.example.comprod.example.com –  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

 
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.