Amongst a few other rewrites, I want to be able to force https on selected url’s and consequently force http for everything else.
I’ve been searching for hours and trying different methods but they’re resulting in the same thing happening so I believe there’s a conflict between some of my rewrites - I’m struggling to see what that is though so I’m hoping to get some advice.
Heres my htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_METHOD} ^TRACE [NC]
RewriteRule .* - [F]
###
### Track download of particular file types
###
RewriteCond %{HTTP_HOST} ^www.example.org [NC]
RewriteCond %{REQUEST_URI} !^/robots\\.txt$ [NC]
RewriteCond %{REQUEST_URI} !^/robots/robots1\\.txt$ [NC]
RewriteRule \\.(zip|zipx|gzip|rar|tar\\.gz|7z|deb|gz|pkg|sit|sitx|pdf|doc|docx|xls|xlsx|txt|rtf|wpd|wps|pps|ppt|pptx|psd|eps|ai|psd|eps|tif|tiff|eps|aac|aif|iff|m3u|mid|midi|mp3|mp4|mpa|ra|wav|wma|3g2|3gp|asf|asx|avi|mov|mpg|rm|vob|wmv|flv|f4v)$ /Download.php?dll=%{REQUEST_URI}&site=1 [L]
###
### CMS can handle multiple sites on their own domains so each has its own robots.txt
###
RewriteCond %{HTTP_HOST} ^www.example.org [NC]
RewriteCond %{REQUEST_URI} ^/robots\\.txt$ [NC]
RewriteRule ^ /robots/robots1.txt [L]
###
### Force trailing slash
###
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_URI} !(\\.[^/]*|/)$ [NC]
RewriteRule ^ %{REQUEST_URI}/ [R=301,L]
###
### Force 'www'
###
RewriteCond %{HTTP_HOST} ^example.org [NC]
RewriteRule ^(.*)$ http://www.example.org/$1 [R=301,L]
###
### Force https for certain parts of website
###
RewriteCond %{HTTPS} off [NC]
RewriteCond %{HTTP_HOST} ^www.example.org [NC]
RewriteCond %{REQUEST_URI} ^/(([^/]+/)*([^/]+)/login|login|([^/]+/)*([^/]+)/payment|payment)/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
###
### Force http for everything else
###
RewriteCond %{HTTPS} on [NC]
RewriteCond %{HTTP_HOST} ^www.example.org [NC]
RewriteCond %{REQUEST_URI} !^/(([^/]+/)*([^/]+)/login|login|([^/]+/)*([^/]+)/payment|payment)/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]
###
### Take last part of uri and pass into constructor to get content
###
RewriteCond %{HTTP_HOST} ^www.example.org [NC]
RewriteRule ^([^/]+/)*([^/]+)/$ /pages/index1.php?site=1&ref=$2&%{QUERY_STRING} [L]
RewriteCond %{HTTP_HOST} ^www.example.org [NC]
RewriteRule ^$ /pages/index1.php?site=1&ref=index&%{QUERY_STRING} [L]
With the force https and force http sections in place:
https://www.example.org/something/
is correctly changed to
http://www.example.org/something/
however,
http://www.example.org/login/
becomes
http://www.example.org/pages/index1.php?site=1&ref=login
If I remove the force http section
the https part works just fine;
http://www.example.org/login/
becomes
https://www.example.org/login/
The only issue with the above is that users are then likely to stay on https as links are typically relative.
Can anyone help me out here and tell me where I’m going wrong with this?