简体   繁体   中英

htaccess - redirect http to https but only for certain domains

I have two domains pointing to the same place but I only want one of these to redirect all http requests to https.

http://www.thisisme.com should stay as it is

http://thisisme.mydomain.com needs to redirect to https://thisisme.mydomain.com

As an extra rule I need to make sure that http://thisisme.mydomain.com/health_check.php does not redirect.

Here's what I have so far.

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Don't redirect /heath_check.php to https
    RewriteCond %{REQUEST_URI} !(health_check\.php)$

    #This line needs looking at! Should only redirect any xxx.mydomain.com requests to https
    RewriteCond %{HTTP_HOST} mydomain\.com

    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

    # block hidden directories
    RewriteRule "(^|/)\." - [F]

    # This makes the url look pretty for codeigniter...
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>

EDIT!

I actually need to do the opposite if the requested domain is not mydomain.com - it needs to redirect to http is https is requested

要排除www.thisisme.com ,请将以下条件放在RewriteEngine on下面RewriteEngine on或者放在http=>https规则的上方或上方:

RewriteCond %{HTTP_HOST} !^(www\.)?thisisme\.com$ [NC]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM