faqts : Computers : Internet : Web Servers : Apache : Security

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 3 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

Entry

Which is the best way to change url from normal to www .yourdomain name.com

Jun 16th, 2008 04:49
gaurav sabharwal, William Douve, Gauav - www.itchimes.com


OK i think this question goes around many people. There are quite a few
ways of doing this 

1st is your hosting provider can do that for you from the servers end.
for this you would need to contact them and they can do it. 

2nd is creating a .htaccess file. and adding a code: 
how to create one: 
Open your notepad on computer. 

add the following code: 
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mydomain\.org [NC]
RewriteRule (.*) http://www.mydomain.org/$1 [R=301,L]

and

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

save the file / save file as .htaccess ( note the file type is not txt
or any format its exactly as written above. 

i have used second one on our company website: http://www.itchimes.com  
they are called 301 redirects (permanent ). they are SEO friendly as well. 

The best part is its difficult for others to view this file unless they
are technical. 

there are other methods of code for .htaccess 

here are others depending on different servers and configuration i the
above works fine on apachee..

here are more 301 redirects if you wish to redirect a page or something :
ColdFusion Redirect
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com"> 

ASP Redirect
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%> 

ASP .NET Redirect
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script> 

JSP (Java) Redirect
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%> 

CGI PERL Redirect
$q = new CGI;
print $q->redirect("http://www.new-url.com/"); 

Ruby on Rails Redirect
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end

.. I hope the above all information doesn't confuse you much and you are
happy . 

thanks 

Gaurav. 
IT Chimes