Jump to content

Forcing specific files to SSL and non-www with .htaccess


charltondurie

Recommended Posts

I have a PHP pages on my site that I need to be forced to always use SSL and non-www. My site is currently in a subfolder while in development (domain.com.au/site/) and I will be moving it to the root domain in the next few days (domain.com.au)

 

The following code works fine other than redirecting www to non-www when SSL is already called. ie https://www.domain.com.au/site/subscribe.php does not redirect to https://domain.com.au/site/subscribe.php

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.domain.com.au [NC]
RewriteRule ^(.*)$ http://domain.com.au/site/$1 [L,R=301]

RewriteCond %{HTTPS_HOST} ^www.domain.com.au [NC]
RewriteRule ^(.*)$ http://enduromag.com.au/site/$1 [L,R=301]

RewriteCond %{REQUEST_URI} ^/site/subscribe.php [OR]
RewriteCond %{REQUEST_URI} ^/site/administrator.php [OR]
RewriteCond %{REQUEST_URI} ^/site/manage-subscription.php
RewriteRule .* - [E=needhttps:on]

RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:needhttps} =on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.