.htaccess - Remove www site-wide, force https on certain directories and http on the rest? -


firstly, remove www. domain name

http://www.example.com => http://example.com

i directories secure (https), while rest remain http

http://example.com/login => https://example.com/login

obviously needs work conditions, example if types in:

http://www.example.com/login => https://example.com/login

also when people navigate away login page returns http. in .htaccess following done automatically software using , suppose needs there work:

rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule .* ./index.php 

any ideas on how can achieve dream control these things?

thanks in advance!

===================

@gumbo following advice complete .htaccess

rewriteengine on   # remove www host rewritecond %{http_host} ^www\.(.+) rewritecond %{https}s/%1 ^(on(s)|offs)/(.+) rewriterule ^ http%2://%3%{request_uri} [l,r=301]  # force https rewritecond %{https} =off rewriterule ^(login)$ https://%{http_host}%{request_uri} [l,r=301]  # force http rewritecond %{https} =on rewriterule !^(login)$ http://%{http_host}%{request_uri} [l,r=301]   rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule .* ./index.php   options -indexes 

navigating http://example/login still goes http://example/index.php when should go https://example/login have order wrong?

try these rules:

# remove www host rewritecond %{http_host} ^www\.(.+) rewritecond %{https}s/%1 ^(on(s)|offs)/(.+) rewriterule ^ http%2://%3%{request_uri} [l,r=301]  # force https rewritecond %{https} =off rewriterule ^(login|foo|bar|…)$ https://%{http_host}%{request_uri} [l,r=301]  # force http rewritecond %{https} =on rewriterule !^(login|foo|bar|…)$ http://%{http_host}%{request_uri} [l,r=301] 

you might want add additional conditions change protocol on , head requests not on post requests.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -