redirect non-www to www with .htaccess


Not Rated!1 Star2 Stars3 Stars4 Stars5 Stars

Tags:

How to redirect non-www to www with .htaccess

Redirect help to improve your SEO ranking

 A Simple 301 Redirect

RewriteEngine On
Redirect 301 /oldpage.htm http://www.w3cgallery/newpage.php

Other way to redirect

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^oldpage.html https://www.w3cgallery.com/newpage.html [R=301,L]

 You can use the same procedure above to redirect to another site, if we added the following to your .htaccess file on www.w3cgallery.com

 Redirect non-www to www

example: http://w3cgallery.com to http://www.w3cgallery.com

RewriteEngine On rewritecond %{http_host} ^w3cgallery.com [nc] rewriterule ^(.*)$ http://www.w3cgallery.com/$1 [r=301,nc]

Fortunately a small amount of code within your .htaccess file located at root can solve the canonical problem. What this code does is 301 redirect one form of the site to the other, it’s like you setup an unlimited number of the simple 301 redirects I listed earlier on the fly.

 Redirect non-www to www with index.html to domain name together

Its little hard to do, while you adding non-www to www and index.php to http://www.yourdomain.com/

must use this codes for this, if you use 2 above codes so it might stuck in redirection.

RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ RewriteRule ^index\.html$ http://%{HTTP_HOST}/ [R=301,L]

enjoy.

Warning: .htaccess/php.ini file can stop working your site if you use wrong code, USE ONLY AT YOUR OWN RISK!

Share/Save/Bookmark

Leave a Reply


CSS (Design) - TOP.ORG