Difference between revisions of "X-Cart:Configuring HTTPS"

From X-Cart 4 Classic
Jump to: navigation, search
m
m
Line 101: Line 101:
  
 
<pre>$xcart_dir = rtrim(realpath($xcart_dir), XC_DS);</pre>
 
<pre>$xcart_dir = rtrim(realpath($xcart_dir), XC_DS);</pre>
 +
<br /><br />
  
 
<div id="https_for_all_pages"> </div>
 
<div id="https_for_all_pages"> </div>
'''Setting HTTPS for all the site pages'''<br />
+
'''Setting HTTPS for the entire X-Cart store site'''<br />
<test>
 
  
<test>
+
Attention! Before switching your site to HTTPS, you must obtain an SSL certificate and have it properly installed and configured on your web server. You also need to monitor your SSL certificate expiration date and be ready to renew it when necessary.
 +
<br /><br />
 +
'''Method 1. Web servers with support for .htaccess, like apache'''
 +
<br />
 +
If you are using a web server of the above-named type, you can add the following code to the .htaccess file
 +
after the line "RewriteBase":
 +
<pre>
 +
RewriteCond %{HTTPS} off
 +
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 +
</pre>
 +
If the canonical URL of your site is known, it is even better to add the following rules:
 +
<pre>
 +
RewriteCond %{HTTPS} off
 +
RewriteRule ^(.*)$ https://example.com/$1 [^] [R=301,L]
 +
</pre>
 +
(Be sure to replace "example.com" with your actual canonical URL).
 +
The above code should be added before the code for handling Clean URLs.
  
<test>
+
You can also use the following instructions:
 +
https://www.sslshopper.com/apache-redirect-http-to-https.html
 +
<br /><br />
 +
'''Method 2. Servers like nginx.conf'''<br />
 +
Convert the rules cited in Method 1 above
 +
to nginx.conf
 +
as follows:
 +
<pre>
 +
server {
 +
    listen 80 default_server;
 +
    listen [::]:80 default_server;
 +
    server_name _;
 +
    return 301 https://$host$request_uri;
 +
}
 +
</pre>
 +
For more info, see:
 +
https://www.bjornjohansen.no/redirect-to-https-with-nginx
 +
<br /><br />
 +
'''Method 3. Only recommended if you cannot use Method 1 or Method 2 above'''
  
<test>
+
X-Cart versions 4.7.9 and later:<br />
 +
To switch your entire X-Cart store to HTTPS, simply select the option 'On all pages' from the 'Use secure protocol (HTTPS)' selector:
 +
https://demo.x-cart.com/demo_goldplus/admin/configuration.php?option=Security#tr_use_https_login
 +
 
 +
X-Cart versions prior to 4.7.9:<br />
 +
To switch your entire X-Cart store to secure mode, edit the file https.php. Find the line:
 +
<pre>
 +
function is_https_link($link, $https_scripts) {
 +
</pre>
 +
and replace it with
 +
<pre>
 +
function is_https_link($link, $https_scripts) {
 +
return true;
 +
</pre>
  
<test>
 
  
 
[[Category:X-Cart user manual]]
 
[[Category:X-Cart user manual]]

Revision as of 18:58, 13 November 2017

Firstly, you should obtain an SSL certificate and have it properly installed and configured on your web server.

The majority of hosting companies help their customers to purchase SSL certificates or provide their own Shared SSL URLs. If your hosting company doesn't render such services, you will need to purchase a certificate on your own.

We will be glad to assist you with this issue. You can purchase SSL certificates from our company. We sell SSL certificates provided by the world's leading Certification Authority, Comodo Group. For details, conditions and prices, please see http://www.x-cart.com/ssl/.

If you are on a dedicated server, we can offer you our service on analyzing and configuring your server and/or install the SSL Certificate on it. Please note: we will need the 'root' access to your server over SSH or the 'Administrator' access over MS Remote Access Desktop to complete these tasks.

Secondly, once you have the SSL certificate installed and configured, you should configure the HTTPS server in X-Cart. To do it, modify the <xcart_dir>/config.php file and set the $xcart_https_host variable properly:

/**
* X-Cart HTTP & HTTPS host and web directory
*
* This section defines the location of your X-Cart installation. If X-Cart is
* installed using Web installation, the variables of this section are
* configured via the Installation Wizard. If you install X-Cart manually, use
* this section to provide your web server details manually.
*
* $xcart_http_host - Host name of the server on which your X-Cart software is
* to be installed;
* $xcart_https_host - Host name of the secure server that will provide access
* to your X-Cart-based store via the HTTPS protocol;
* $xcart_web_dir - X-Cart web directory.
*
* NOTE:
* The variables $xcart_http_host and $xcart_https_host must contain hostnames
* ONLY (no http:// or https:// prefixes, no trailing slashes).
*
* Web dir is the directory where your X-Cart is installed as seen from the Web,
* not the file system.
*
* Web dir must start with a slash and have no slash at the end. An exception to
* this rule is when you install X-Cart in the site root, in which case you need
* to leave the variable empty.
*
* EXAMPLE 1:
* $xcart_http_host ="www.yourhost.com";
* $xcart_https_host ="www.securedirectories.com/yourhost.com";
* $xcart_web_dir ="/xcart";
* will result in the following URLs:
* http://www.yourhost.com/xcart
* https://www.securedirectories.com/yourhost.com/xcart
*
* EXAMPLE 2:
* $xcart_http_host ="www.yourhost.com";
* $xcart_https_host ="www.yourhost.com";
* $xcart_web_dir ="";
* will result in the following URLs:
* http://www.yourhost.com/
* https://www.yourhost.com/
*/

Finally, enable the secure checkout at your store by selecting the HTTPS protocol for the payment methods to be secure on the Payment Methods page. You can also adjust these HTTPS options on the 'General settings/Security options' page:

Optionally, if you need secure certain php scripts you should add https scripts to <xcart_dir>/https.php file, 'https_scripts' array. You can find some examples in <xcart_dir>/https.php file:

$https_scripts[] = 'login.php';
$https_scripts[] = array(
'cart.php',
"mode=checkout",
);

Optionally, if you want to switch the whole x-cart to secure mode edit https.php file. Find the line

function is_https_link($link, $https_scripts) {

and replace it with

function is_https_link($link, $https_scripts) {
return true;

Now, if your web server does not use SSL certificates, and you are running an HTTPS Proxy instead, you may need to make additional settings to enable your X-Cart work over SSL (secure connection). In the include/https_detect.php file, define the proxy IP address and set the $HTTPS variable to 'true':

if ($_SERVER['REMOTE_ADDR'] == '192.160.1.1') {
$HTTPS_RELAY = true;
$HTTPS = true;
}

If you are not sure whether your web server uses SSL certificates or runs behind an HTTPS Proxy, contact your hosting service provider or server administrator or email our technical support - we will help you find that out.

If you experience problems with external services (payment / shipping) working over https while using curl/libcurl as the https module, try adding the following line to top.inc.php:

define('USE_CURLOPT_SSL_VERIFYPEER', 1);

after

$xcart_dir = rtrim(realpath($xcart_dir), XC_DS);



Setting HTTPS for the entire X-Cart store site

Attention! Before switching your site to HTTPS, you must obtain an SSL certificate and have it properly installed and configured on your web server. You also need to monitor your SSL certificate expiration date and be ready to renew it when necessary.

Method 1. Web servers with support for .htaccess, like apache
If you are using a web server of the above-named type, you can add the following code to the .htaccess file after the line "RewriteBase":

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

If the canonical URL of your site is known, it is even better to add the following rules:

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

(Be sure to replace "example.com" with your actual canonical URL). The above code should be added before the code for handling Clean URLs.

You can also use the following instructions: https://www.sslshopper.com/apache-redirect-http-to-https.html

Method 2. Servers like nginx.conf
Convert the rules cited in Method 1 above to nginx.conf as follows:

 
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

For more info, see: https://www.bjornjohansen.no/redirect-to-https-with-nginx

Method 3. Only recommended if you cannot use Method 1 or Method 2 above

X-Cart versions 4.7.9 and later:
To switch your entire X-Cart store to HTTPS, simply select the option 'On all pages' from the 'Use secure protocol (HTTPS)' selector: https://demo.x-cart.com/demo_goldplus/admin/configuration.php?option=Security#tr_use_https_login

X-Cart versions prior to 4.7.9:
To switch your entire X-Cart store to secure mode, edit the file https.php. Find the line:

function is_https_link($link, $https_scripts) {

and replace it with

function is_https_link($link, $https_scripts) {
return true;