Redirect through .htaccess file

Here’ s the logic to redirect particular page through .htaccess file.

RewriteCond %{HTTP_HOST} ^avidindiainc.com [NC]
RewriteRule ^(.*)$ http://www.avidindiainc.com/$1 [L,R=301]

as given above,
here avidindiainc.com is the url of the site you want to redirect. here if the url typed in the address bar is http://avidindiainc.com, it will redirect to http://www.avidindiainc.com.

the above given logic will work for apache webserver only as .htaccess file is supported by apache webserver and not IIS webserver. In case you have an IIS webserver here’s something you can do.

But this logic has to be written in php file. The logic follows as below:

<?php

if($_SERVER[‘SERVER_SOFTWARE’]==’Microsoft-IIS/6.0′){
if($_SERVER[‘HTTP_HOST’]!=’www.theartel.com’){
header( “HTTP/1.1 301 Moved Permanently” );
if($_SERVER[‘argv’])
header( “Location: http://www.&#8221;.$_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’].’?’.@implode(‘&’,$_SERVER[‘argv’]));
else
header( “Location: http://www.&#8221;.$_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’]);
}
}


?>

thanks,

Sachin

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s