Create and use .htaccess file to fix 301 error in a website

What is a .htaccess File :

.htaccess a file type which is used by seo experts for various issues occurred with a website. The most popular way to use a .htaccess file is for 301 redirection, that is to redirect non www url to www and www to without www. we just need to put some line of codes in a file and then we upload that on the server through ftp access. We upload the file in the same root where .index file is placed.

Recommended post : Know Meta tagsĀ 

How to create .htaccess File

To create a .htaccess file please follow the below steps :

  • Create a text document
  • Paste the required .htaccess code
  • Now click on save as
  • write file name as .htaccess
  • select all types in save as type option.
  • Now click on save. the .htaccess file will be created.
Create .htaccess file

.htaccess code to remove 301 error – non www to www or www to without www redirection in a website

Please paste the below code in your text document while creating the .htaccess file.

Code for www to non www redirect

RewriteEngine On RewriteCond %{HTTP_HOST} ^ [NC] RewriteRule ^(.*)$$1 [L,R=301]

code for non www to www redirect

RewriteEngine On RewriteCond %{HTTP_HOST} ^ [NC] RewriteRule ^(.*)$$1 [L,R=301]
All you need is to replace with your own website name. and do remember you have to upload this .htaccess file to the same path where .index page is present.

Thanks for being here. If you have any problem feel free to ask me in the comment section !!

Also know : How to fix /index.html error to home page in a website
: How to redirect Single/multiple Pages to another page in a website

Leave a Reply

Your email address will not be published. Required fields are marked *