Force www with htaccess

By Admin - June 26, 2017 11:59 pm   1   175   0

Htaccess is Hypertext Access and it is configuration file used by Apache based web servers. It is also helpful for better SEO Every client want their website's url attractive and don't want to display the query strings id's to users. Google analytic reports always force to keep www before your domain name and it is better for SEO. So here's the solution. You can force your website's url to open website with www before domain name everytime it opens with simple one line code.

Before URL :

After URL :

Steps :-

  1. Create the new file with name .htaccess in website root folder.
  2. Now Apache Server can read the htaccess rules.
  3. Write this code in .htaccess file.
  4. RewriteEngine must be On in your htaccess file otherwise it will not work.
    • RewriteEngine On
      RewriteCond %{HTTP_HOST} ^ [NC]
      RewriteRule ^(.*)$$1 [L,R=301,NC]
  5. Save .htaccess file and run your website on web browser and server will automatically write www before your domain name.