Christophe Posted June 1, 2017 Author Share Posted June 1, 2017 @rick I'm talking about 2 different websites that have nothing in common. For each website, the 4 variations of the url point to the same (common) content. I normally can't use sites-available/sites-enabled (only on my local computer(s). Ex-Ubuntu and current Linux Mint Mate user). @szabesz I'll use it eventually and see if it works for me. Edit: it doesn't work (at least for the domain I'm currently working on). https://www.domain.tld is redirected to http://domain.tld. @SiNNuT I think I have it bookmarked and perhaps also downloaded it somewhere. Edit 2: now that I want to use the non-www version, I have to find a way to change the code I was using so that it works... So much time wasted for things that should be easier to do. Edit 3: there seems to be a difference, related to shared cookies, between the www and non-www choices. Edit 4: I'll eventually try again later with other domains. It's not worth it now. 1 Link to comment Share on other sites More sharing options...
szabesz Posted June 1, 2017 Share Posted June 1, 2017 I edited my previous post too by adding this one to it: Link to comment Share on other sites More sharing options...
szabesz Posted June 1, 2017 Share Posted June 1, 2017 3 hours ago, Christophe said: @szabesz I'll use it eventually and see if it works for me. Edit: it doesn't work (at least for the domain I'm currently working on). https://www.domain.tld is redirected to http://domain.tld. Did you also uncomment this one? # ----------------------------------------------------------------------------------------------- # 9. If you only want to allow HTTPS, uncomment the RewriteCond and RewriteRule lines below. # ----------------------------------------------------------------------------------------------- # RewriteCond %{HTTPS} off # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] Link to comment Share on other sites More sharing options...
Christophe Posted June 1, 2017 Author Share Posted June 1, 2017 9 hours ago, szabesz said: # ----------------------------------------------------------------------------------------------- # 9. If you only want to allow HTTPS, uncomment the RewriteCond and RewriteRule lines below. # ----------------------------------------------------------------------------------------------- # RewriteCond %{HTTPS} off # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] @szabesz Of course I tried also with this. Too many redirects error message. This doesn't work for me (at least while testing it with one of the websites). For exemple, http://www is not even redirected to http:// I'm not going to spend more time with this now. Later eventually. I'd like a debugger to exist for this. Perhaps using a security/penetration testing framework(?). Thanks everyone. 1 Link to comment Share on other sites More sharing options...
gurkendoktor Posted June 1, 2017 Share Posted June 1, 2017 You can alway see the headers (and thus your redirects) by using curl -vL http://your.domain/ at the command line (if you have cURL installed). At the same time you can check the server logs (access log) and you will see what site is being accessed. 1 Link to comment Share on other sites More sharing options...
Christophe Posted June 1, 2017 Author Share Posted June 1, 2017 First solution for the website at ovh (registar and website hoster). Found this again (and that I had bookmarked it already):https://docs.ovh.com/fr/fr/web/hosting/htaccess-reecriture-url-mod-rewrite/ If not wrong, using this RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.domainname.tld/$1 [R=301,L] Then this RewriteCond %{HTTP_HOST} ^domainname.tld$ RewriteRule ^(.*) http://www.domainname.tld/$1 [QSA,L,R=301] I only have a 2 redirect message with PageSpeed Insights - if testing https://domainname.tld If I use this instead RewriteCond %{HTTP_HOST} ^domainname.tld$ RewriteRule ^(.*) https://www.domainname.tld/$1 [QSA,L,R=301] I don't have redirect error messages anymore (4 combinations/variations). I'll (re)check again to see if it was real. And I'll test later if I can easily transform it to use the non-www version. But I'm not sure if I really want the non-www version or not. I'll precise R=301 where there is only R. It's very easy to invert from www to non-www. Apparently no redirect error messages either. So it's ok now for this one website. I would just have to choose between www and non-www. http://www.yes-www.org/http://www.yes-www.org/why-use-www/ (technical reasons) 1 Link to comment Share on other sites More sharing options...
gurkendoktor Posted June 2, 2017 Share Posted June 2, 2017 Just choose one and stick with it. While you ponder and tinker, use 302. Once you're sure and live, use 301. After a while everything will automatically point to the canonical URL as this is the one that gets distributed and listed in $search_engine. Link to comment Share on other sites More sharing options...
Christophe Posted June 6, 2017 Author Share Posted June 6, 2017 Also resolved it for the other hoster. Same, but with RewriteCond %{HTTP:X-Forwarded-Proto} !https added. So RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.domainname.tld/$1 [R=301,L] And RewriteCond %{HTTP_HOST} ^domainname.tld$ RewriteRule ^(.*) https://www.domainname.tld/$1 [QSA,L,R=301] NB: the redirection from https:// to https://www seems to work better when keeping RewriteCond %{SERVER_PORT} 80 after adding RewriteCond %{HTTP:X-Forwarded-Proto} !https Tested several times, with the cache cleared. Perhaps a coincidence, or not... I was just curious to see what would happen if I removed it. 2 Link to comment Share on other sites More sharing options...
AndZyk Posted June 21, 2017 Share Posted June 21, 2017 @Christophe Thank you for your solution, it works well. Just a small typo: On 7.6.2017 at 1:18 AM, Christophe said: RewriteCond %{HTTP_HOST} ^domainname.tld$ RewriteRule ^(.*) https://www.domainname.tld/$1 [QSA,L,R=301] 1 Link to comment Share on other sites More sharing options...
Recommended Posts