301 redirect URL by .htaccess (Apache)

While I was optimizing my website, I realized links to our website was splitted with two URLs, www.ipBalance.com and ipBalance.com. It’s definitely not good for popularity indexed by Google and even other searching engineers. Then I have decided picking one permanant name and applied 301 redirect URL. I went simple route to set that up using cpanel function, but it doesn’t work for me. Other way was using an .htaccess file at hosting server. Due to bad experience with .htaccess file previously, so I didn’t want to touch it. But it was fairly straight forward to complete 301 redirect URL. 

Open an .htaccess file and edit with below context.
** This will work ONLY on Linux servers having the Apache Mod-Rewrite module enabled.

 

 

 

www.ipBalance.com —> ipBalance.com

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

 

ipBalance.com —> www.ipBalance.com

Options +FollowSymLinks
RewriteEngine On
rewritecond %{http_host} ^ipbalance.com [nc]
rewriterule ^(.*)$ http://www.ipBalance.com/ [r=301,nc]

 

www.ipBalance.com —> ipBalance.com/index.php

Options +FollowSymLinks
RewriteEngine On
rewritecond %{http_host} ^www.ipbalance.com [nc]
rewriterule ^(.*)$ https://ipbalance.com/$1 [r=301,nc]

 

** Rare case, you might see some links are broken in 1~2 minutes due to cashe on your application/ CMS. Patient!.

 

Leave a Reply