0

I made my entire site https by changing the unsecure_url to https rather than http. Then in my .htaccess I added:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]

RewriteCond %{HTTP_HOST} !^www\.MYSITE\.co.uk 
RewriteRule (.*)http://www.MYSITE.co.uk/$1 [R=301,L]

However, I'm faced this the weird issue of having a double trailing slash the end of my URL's when I visit my site via:

  1. http://www.mysite.co.uk
  2. mysite.co.uk
  3. https://mysite.co.uk

However, I am lost as to why the double trailing slashes is occurring, would anyone be able to kindly help myself? Auto-redirect to Base URL config is also set to:

YES ("301 moved permanently")

Check the Network tab in Firefox I can see that when accessing the site as https://mysite.co.uk it will redirect to http://www.mysite.co.uk then https://www.mysite.co.uk. However, www.mysite.co.uk will correctly direct to https:www.mysite.co.uk.

0

This is the code I use to redirect all http traffic to their corresponding https pages, same as yours except the trailing slash.

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • I have amended my http to https without the trailing slash, I think the issue is the non-www to www – Vaishal Patel Jun 29 '18 at 6:43
0

I was able to overcome the issue of double redirects and double forward slashes with the following:

############################################
## 301 redirect for http to https
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://www.example.co.uk%{REQUEST_URI} [R=301,L]

############################################
##SETTING THE PREFERENCE TO BE WWW##

RewriteCond %{HTTP_HOST} !^www\.example\.co.uk
RewriteRule ^(.*) https://www.example.co.uk/$1 [R=301,L]

Instead of relying on the HTTP_HOST, which is obtained from the HTTP request header and this is what the client actually used as "target host" of the request.

I implicitly set in the http to https rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.