Quantcast
Channel: Help
Viewing all articles
Browse latest Browse all 8

How to redirect all queries from non www to www and www to non www with .htaccess??

$
0
0

Duplicate contents are always a hindrance to your search engine rankings, especially Google considers duplicate entries with it's utmost seriousness. The main reason for duplicate contents are mere carelessness or technical issues.

When it comes to carelessness we can take the case of urls with www and non www in it. Most of the sites which are not SEO optimized allow requests from www and one without www. The end result is the creation of duplicate content, in short there will be two URL which points to the same content (one with www in URL and one without www). This will create serious issues in your search engine rankings.

So how to redirect all request from a non www URL to www URL?

Please add this code in your htaccess (or .htaccess) file with the help of any text editor.

Please select the text "RewriteEngine On" in the htaccess and paste the code below there.

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

Please note that there should not be two lines of "RewriteEngine On" in the htaccess file.

Once finished save the file and upload it to the root of your server's folder.

Now all the requests from a non www URL will be redirected to a www URL.

Now you will be thinking, how to redirect all www requests to non www with the help of same htaccess file. Answer is simple please insert the code below.

Code to redirect www request to non www with htacess (.htaccess)

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

The procedure is same as above.


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images