0

Trying to setup my site so that its on HTTPS AND includes the WWW in the URL.

After a while of searching I found a few posts that helped me redirect to https:

stackoverflow.com/questions/25527671/magento-https-on-all-website-urls-redirect-to-homepage

and then to redirect to get the 'www' added in I used:

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

I ended up with everything working eventually! BUT here is where I think a problem lies. It may be me being niggley BUT when you check a URL now on my site (old redirect URL):

http://aloe-herbal.co.uk/categories/Bee-Hive-Products/pages/Contact-Us.html

it redirects fine BUT then using a 301 redirect checker:

redirect-checker.org/index.php

you can clearly see that there is 2 301 redirects happening here.. I don't think that's ideal..

Initially this was happening 2-3 3 times SO as an example if I used the URL to check as:

aloe-herbal.co.uk/fitness-weight-management.html 
@ www.redirect-checker.org/index.php
it would give me the following:

CONGRATULATION. Everything seems to be fine.

http://aloe-herbal.co.uk/fitness-weight-management.html
301 Moved Permanently
http://www.aloe-herbal.co.uk/fitness-weight-management.html
301 Moved Permanently
https://www.aloe-herbal.co.uk/fitness-weight-management.html
200 OK 

I know it says its okay but I am concerned about the extra trip that its having to make..

So I decided top open a question. Well FIRSTLY thanks for a GREAT related questions feature. WOW gave me a fix straight away:

magento.stackexchange.com/questions/40400/magento-goes-first-the-http-then-redirects-to-https

Works like a charm now there is only 1 301 Moved Permanently listed :)

BUT again if you check: http://aloe-herbal.co.uk/categories/Bee-Hive-Products/pages/Contact-Us.html

you can see its there 2 times again... That's what I am trying to fix/avoid..

Can any experts help with this last part?

3 Answers 3

0

Did you put

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

before

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

in your .htaccess file?

If so, Apache would rewrite http://aloe-herbal.co.uk to https://aloe-herbal.co.uk and stop processing further rules due to the 'L' flag. Then it would get a new request (https://aloe-herbal.co.uk) which would be rewritten to https://www.aloe-herbal.co.uk, hence double redirect. Try putting the 'www.'-adding bit before the HTTPS part.

1
  • hello @maciek YES i did put the www part before the https.. I tested it many ways including the way you have stated NOT to do it.. but adding the rules as you have suggested and as I have implemented doesnt seem to work.
    – Umbrella
    Commented Mar 11, 2015 at 12:15
0

First, make sure that the unsecure as well as secure base URL under System - Configuration - Web is configured to use https. Then try this in your .htaccess:

############################################
## enables the usage of %{ENV:proto} as the protocol (http vs https) in the rewrite rules
    RewriteCond %{HTTPS} =on
    RewriteRule ^(.*)$ - [env=proto:https]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ - [env=proto:http]

############################################
## redirect from non-www to www
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ %{ENV:proto}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
4
  • hello simon, to confirm I have used HTTPS in both unsecure AND secure URL in magento configuration. Also re: htaccess rules, that's contradicting with the advice given by @maciek and doesn't work with my setup. It either breaks OR has multiple redirects.
    – Umbrella
    Commented Mar 11, 2015 at 12:17
  • @Umbrella the htaccess rules I posted above are only doing one redirect. Did you try them?
    – Simon
    Commented Mar 11, 2015 at 12:53
  • yes i did. although it works its NOT ideal as the code you provided has multiple redirects AND has a 302 thrown into it: aloe-herbal.co.uk/categories/Bee-Hive-Products/pages/… 301 Moved Permanently aloe-herbal.co.uk/categories/Bee-Hive-Products/pages/… 302 Found aloe-herbal.co.uk/categories/Bee-Hive-Products/pages/… 301 Moved Permanently aloe-herbal.co.uk/customer-service 200 OK where as the code I am using only has the 2 and NO 302 involved. pls chck @ redirect-checker.org/index.php with lst URL gven 1st post
    – Umbrella
    Commented Mar 11, 2015 at 13:23
  • the code I am currently using is: # Rewrite any request to the wrong domain to use www. RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ %{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Rewrite to HTTPS: RewriteCond %{HTTPS} off # Don't put www. here. If it is already there it will be included, if not # the ABOVE rule will catch it. RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] DOES the job apart from the 2 redirects involved for the URL's referenced in first post...
    – Umbrella
    Commented Mar 11, 2015 at 13:27
0

Forget about all this htaccess rewrite. Set your base url for secure and unsecure in the backend. Set yes on use secure url in frontend in the backend.

Then edit your app/etc/local.xml and include this

<?xml version="1.0"?>
<config>
  <frontend>
     <secure_url>
      <all>/</all>
     </secure_url>
   </frontend>
</config>

Or at least paste the XML tree frontend and lower in between the config tags.

EDITED cause mobile screwed up the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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