Thursday

301 Redirect Non-www to www and index.html(htm,php)

Google, Bing Search Engine Consider these are Separate Domains:
  1. xyz.com
  2. xyz.com/
  3. xyz.com/index.html
  4. xyz.com/index.htm
  5. www.xyz.com
  6. www.xyz.com/
  7. www.xyz.com/index.htm
  8. www.xyz.com/index.html
So you can face Duplicate Website Content issue. Below are code to take care of this issue and 301 permanent redirect all those above listed domains to one single domain. 

.htaccess 301 Redirect Code With HTML Extensions:

        1. 301 permanent redirect index.html(htm) to folder
          RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
         RewriteRule ^(([^/]+/)*)index\.html?$ http://www.xyz.com/$1 [R=301,L]
         
        2. 301 permanent redirect non-www (non-canonical) to www
        RewriteCond %{HTTP_HOST} !^(www\.xyz\.com)?$
       RewriteRule (.*) http://www.xyz.com/$1 [R=301,L]

 X--------------------------X----------------------------------------X
You Can also Put above Two Codes together:

RewriteEngine On
# 301 permanent redirect index.html(htm) to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.xyz.com/$1 [R=301,L]

# 301 permanent redirect non-www (non-canonical) to www
RewriteCond %{HTTP_HOST} !^(www\.xyz\.com)?$
RewriteRule (.*) http://www.xyz.com/$1 [R=301,L]

X--------------------------X----------------------------------------X

.htaccess 301 Redirect Code With PHP Extensions:

 RewriteEngine On
# 301 permanent Redirect index.php to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.xyz.com/$1 [R=301,L]

# 301 permanent Redirect non-www (non-canonical) to www
RewriteCond %{HTTP_HOST} !^(www\.xyz\.com)?$
RewriteRule (.*) http://www.xyz.com/$1 [R=301,L] 



Universal Code: With HTML and PHP Extensions:
 
RewriteEngine On

# 301 permanent Redirect index.html(.htm and .php) to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html?|php)$ http://www.xyz.com/$1 [R=301,L]

# 301 permanent Redirect non-www (non-canonical) to www
RewriteCond %{HTTP_HOST} !^(www\.xyz\.com)?$
RewriteRule (.*) http://www.xyz.com/$1 [R=301,L]

  











6 comments:

  1. It's really worth reading the blog post whcih has useful content. I have recently done CRS Info Solutions which is highly helpful to upgrade my career. What is the Salesforce course training fee in Chennai? Which is the best option from Salesforce Certification Training in Chennai? Who offers job oriented Salesforce training in Chennai? Find the best institute for project based Salesforce training in Chennai.

    ReplyDelete
  2. That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea. thanks once more. increase da

    ReplyDelete
  3. Super site! I am Loving it!! Will return once more, Im taking your food additionally, Thanks. SEO Backlink

    ReplyDelete
  4. You have noted very interesting points! ps nice internet site. https://www.seoexpertindelhi.in

    ReplyDelete
  5. If you are looking for more information about flat rate locksmith Las Vegas check that right away. ניו זילאַנד עטאַ

    ReplyDelete
  6. I think that thanks for the valuabe information and insights you have so provided here. dating site reviews

    ReplyDelete