Forum Moderators: phranque

Message Too Old, No Replies

How to exclude a subdomain for a 'Force to https' rule

         

stemc

3:36 am on Feb 17, 2010 (gmt 0)

10+ Year Member



Hi there,

On my Apache 2 web server (also running PHP 5 and a PHP/MySQL CMS), I'm currently using the following .htaccess rule in order to force the user to the https version of the website:

RewriteEngine On

# Force https instead of http
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]


I've just added a development subdomain for testing purposes, [dev.example.com,...] but I've found that the above rule is preventing me from accessing this subdomain.

I'd appreciate it if someone could tell me what I need to do to the above code in order to make this new dev subdomain load without being forced to the above URL.

Thanks for any help,

Stephen

[edited by: jdMorgan at 2:16 pm (utc) on Feb 17, 2010]
[edit reason] example.com [/edit]

g1smd

9:12 am on Feb 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add a negative match RewriteCond looking at HTTP_HOST to exclude that subdomain from being redirected.


Your [R] produces a 302 redirect. You'll likely need R=301 instead.


You'll also need a rule to 'force to HTTP' all those URL requests that should not be served as HTTPS.