Make the redirects from http:// to www

When you try to add a new account to webmaster tool, you may face a problem that Google treat a non www link different than (www) .

so you have to do one of the following :

  1. Add the both links ( that is not a good idea for doing that )
  2. Add a code to redirect to ( http://) to (http://www) , and we can do that in .htaccess 

# Redirect www to non-ww
#RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
#RewriteRule ^(.*)$ <a href="http://%251/$1">http://%1/$1</a> [R=301,L]
<span style="line-height: 1.5em;"><ifmodule mod_rewrite.c></span>
RewriteEngine On
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ <a href="http://www.%25%7bHTTP_HOST%7d/$1">http://www.%{HTTP_HOST}/$1</a> [R=301,L]
</ifmodule>

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: