How To Redirect non-www to www URL with .htacess

Wanna Learn How To Create A Website? Ask Question Related To Blogging, Web Design, Programming, Forum Software, CMS etc.
Post Reply
User avatar
admin ~ ~  
Site Admin
Posts: 251
Joined: Thu Dec 14, 2017 5:16 pm
Cash on hand: Locked

How To Redirect non-www to www URL with .htacess

#1

Post by admin » Tue Mar 20, 2018 4:54 pm

Image
Sequel to the post made by @IPman on which is preferable between www and non-www URL.
When you set your preferred URL in Google webmaster tool, it is important that you link the chosen URL version to the one you didn't choose.
For instance, when you choose www.example.com as your preferred URL, you also need to redirect example.com to it (can be done vice versa), in order to prevent google from seeing your website as two which will make your contents to be seen as duplicate content and it will affect your ranking on search engine.
In this tutorial I'll show you how to set 301 redirect with .htacess of your website.

1. Redirect www to non-www
To redirect www to non-www URL version of your website, copy the code below and add it to the .htacess of your website.

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
2. Redirect non-www to www
To redirect non-www URL version of your website, copy the code below and add it to the .htacess of your website.

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Note: Replace example.com with your own URL

Please drop your questions below if any.

(Quote)






SHARE WITH FRIENDS


eastatlantaniqqa ~ ~  
Posts: 18
Joined: Sun Jan 21, 2018 10:28 am
Cash on hand: Locked

How To Redirect non-www to www URL with .htacess

#2

Post by eastatlantaniqqa » Sat Apr 07, 2018 2:00 am

I want to replace my. blogspot domain with a. com
domain please how do I go about it ?

(Quote)

User avatar
admin ~ ~  
Site Admin
Posts: 251
Joined: Thu Dec 14, 2017 5:16 pm
Cash on hand: Locked

How To Redirect non-www to www URL with .htacess

#3

Post by admin » Mon Apr 16, 2018 5:08 pm

eastatlantaniqqa wrote:
Sat Apr 07, 2018 2:00 am
I want to replace my. blogspot domain with a. com
domain please how do I go about it ?
Read this tutorial to get started
How To Change A .Blogspot To .Com

(Quote)


POST COMMENT

   


  •  LOGIN