Wednesday, August 26, 2015

Force www or non-www Prestashop

Today I encountered a very weird  issue my web portal made via Prestashop was opening  with non www and showing a blank screen on www.sitename.com. Prestashop webportals avoids double content in search engines, so by default the access can be given to either www or non www by prestashop portal but the customer is not aware what to type just your site name or www.sitename so to avoid conflict its better to keep both the urls but the www url should 301 redirect to the non www portal lets see how to do this.
Steps to update this setting:



Step 1: Open your ftp from file manager or using some software

Step 2:  Navigate to /public_html folder
Step 3: Open .htaccess file
Step 4: Add these lines to your .htaccess file
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.sitename\.com [NC]
RewriteRule ^(.*)$ http://sitename.com/$1 [L,R=301]
 these steps can be used to rewrite www full domains either. Just add these lines to .htaccess file
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^
sitename.com [NC]
RewriteRule ^(.*)$ http://www.
sitename.com/$1 [L,R=301,NC]
 Now, when you type in your domain name with either www in front or not, it should display as you have set it in the .htaccess file.

 NOTE: Do not place both Codes www and non www in the .htaccess file as it will cause an error.



No comments:

Post a Comment