Welcome to WebmasterWorld Guest from 35.175.182.106

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Htaccess and forced www

     
9:33 am on Mar 21, 2018 (gmt 0)

Senior Member

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

joined:Oct 25, 2006
posts: 1088
votes: 1


I have tested code inside Mozilla and Chrome. How to force also inside Chrome forced https://www.example.com

When I put inside Chrome www.example.com it will not be forced to my desired URL and HTTPS.

Demo version: 
<IfModule mod_rewrite.c>
RewriteEngine On
# Force SSL for CP requests
RewriteCond %{HTTP_HOST} ^example\.com [NC]
# RewriteCond %{REQUEST_URI} ^/admin/ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
</IfModule>

[edited by: phranque at 11:03 am (utc) on Mar 21, 2018]
[edit reason] unlinked url [/edit]

11:01 am on Mar 21, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11468
votes: 174


(i am assuming your canonical hostname is example.com and not www.example.com)

i would try using something like this (you don't need the IfModule container):
RewriteEngine On
# Force secure protocol and canonical hostname for CP requests
RewriteCond %{HTTP_HOST} !^(example\.com)?$ [NC,OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]


and make sure to clear your browser cache before testing the changes.

[edited by: phranque at 4:05 am (utc) on Mar 22, 2018]

8:16 pm on Mar 21, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15314
votes: 709


These redirects are issued by the server in response to all requests; your RewriteRules don't have a USER_AGENT condition. So the only way the choice of browser can possibly be a factor is if an earlier response has been cached. Emptying your browser cache never hurts--it's one of the standard Fixes For What Ails You--but most of the time a forced refresh (Reload button) should also work.
9:12 am on Mar 22, 2018 (gmt 0)

Senior Member

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

joined:Oct 25, 2006
posts: 1088
votes: 1


Thank you for these replies.
I have managed using CP and it works but I like to solve using HTACCESS.
Domain: example.com
Redirect Url: https://www.example.com/
Type: permanent
Wildcard: OK

Which HTACCESS should be used as your example will not work in my case?