2

The checkout/onepage is working with HTTPS. But, why checkout/cart is not?

Here is fragment of the .htaccess:

############################################
## enable rewrites

Options +FollowSymLinks
RewriteEngine on
# RewriteCond %{REQUEST_URI} checkout\/onepage
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} checkout/
# RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^checkout/$ https://idfr.com/checkout/ [R=301,L]

############################################
  • Apache version: Apache/2.4.7 (Ubuntu)
  • operating system: Windows 8.1
  • indications in the log files; Main ErrorLog: "/var/log/apache2/error.log"
  • 1
    Are you saying that checkout/cart does not redirect to HTTPS, or it simply does not work when accessed over HTTPS? Your current rule will not redirect checkout/cart, but neither will it redirect checkout/onepage. (?) What "indications in the log files"? – MrWhite Nov 24 '15 at 23:47
1

Place in your /checkout/ folder a htaccess with this content:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

It will rewrite all requests, which aren't secure (not coming to port 443) to https-ed url.

Another way

Place at the beginning of your files onepage and cart following PHP code snippet:

<?php
if ($_SERVER["SERVER_PORT"] != 443) {
$redir = "Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header($redir);
header("HTTP/1.1 301 Moved Permanently");
exit();
}
?>

which does the same.

1

I think this line might be the problem:

RewriteRule ^checkout/$ https://idfr.com/checkout/ [R=301,L]
        ----^     ----^

This line rewites the url if the url 'starts with' (^) and 'ends with' ($) the string 'checkout'. Because you have no wildcards like * or ., this line now means "literally checkout/, nothing else".

This means that checkout/ will match, but checkout/example will not, because it doesn't match the rewrite rule conditions.

# force ssl
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} ^/checkout
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

This snippet does:

  • If we are HTTP (which uses port 80)
  • AND the url starts with /checkout (Depending on your server, the slash might not be needed)
  • ->Redirect to https version

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.