How to redirect non-www URLs to www Opencart



How to redirect non-www URLs to www?

Redirecting Non WWW to WWW :

Why we do this, sometimes we using images /icons from other websites i.e awesomeicons etc, so if we access our website without www the icons not showing. This is one of the reason we use redirects.

  1. Create a .htaccess in the root of your website. Put the following code, save it.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.velsat\.com\.my$
RewriteRule ^(.*)$ http://velsat.com.my/$1 [L,R=301]


  1. Goto config.php on your opencart main directory and in admin directory too.

Add www before your domain name. 
config.php


<?php
// HTTP
define('HTTP_SERVER', 'http://www.velsat.com/');

// HTTPS
define('HTTPS_SERVER', 'http://www.velsat.com/');

config.php/ Admin

<?php
// HTTP
define('HTTP_SERVER', 'http://www.velsat.com.my/adminx/');
define('HTTP_CATALOG', 'http://www.velsat.com/');

// HTTPS
define('HTTPS_SERVER', 'http://www.velsat.com/admiz/');
define('HTTPS_CATALOG', 'http://www.velsat.com/');

you are DOne..!

But wait did you check your admin Panel, may be it won't work because of the session

what you do it just Remove www from the admin Config.php file. 

Enjoy.

1 comment:

  1. Redirect Using cPanel
    Lazy Way to Redirect Using .htaccess

    If your website is hosted with a provider that uses cPanel, you can even set up your redirects without touching a line of code. This actually adds the redirect rule directly to the .htaccess file, but sometimes I’d rather not get my hands dirty. To do this, log in to your cPanel, and go to Redirects.

    Redirect WWW to non-WWW:


    Redirect non-WWW to WWW:

    More details https://authoritylabs.com/blog/solving-canonical-problems/

    ReplyDelete