how to setup 301 redirect from non-www to www and subfolder

I wanted to redirect our website http://greenecosystem.in to http://www.greenecosystem.in/fconn i.e. two redirects as below,
1. greenecosystem.in to www.greenecosystem.in [ non-www to www ] 2. www.greenecosystem.in or greenecosystem.in to www.greenecosystem.in/fconn [ from root to subfolder of root ]

Here is what .htaccess solved the problem,

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

The first RewriteEngine does is do 301 redirect from greenecosystem.in to www.greenecosystem.in
and second RewriteEngine does is redirect www.greenecosystem.in to www.greenecosystem.in/fconn

READ  How to fix: Your connection to this site is not fully secure in Chrome, Firefox OR any other browsers

How to verify your websites current redirects,
Just type your domain name in http://redirectcheck.com/index.php and click Trace, or you can also use http://www.redirect-checker.org

 

For more help refer below URLs :

https://www.namecheap.com/support/knowledgebase/article.aspx/9410/29/how-to-setup-rules-and-redirects-in-htaccess

https://moz.com/learn/seo/redirection

https://support.google.com/webmasters/answer/93633

You can also refer to good information at https://gist.github.com/ScottPhillips/1721489

 

Leave a Reply

Your email address will not be published. Required fields are marked *