charltondurie Posted November 18, 2009 Share Posted November 18, 2009 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] Link to comment https://forums.phpfreaks.com/topic/181980-forcing-specific-files-to-ssl-and-non-www-with-htaccess/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.