Why use 301 redirect?
Answer: You can use 301 redirection to redirect the domain name without www to the domain name with www. This can direct all the weight to the domain name with www, which is very helpful for website optimization.
How to implement 301 redirect in code?
Answer: This can be achieved by adding the following code to the database connection file.
<%
Dim Server_Name,Path_infostr,Query_Stringstr
Path_infostr=lcase(request.ServerVariables(PATH_INFO))
Server_Name=lcase(request.ServerVariables(Server_Name))
Query_Stringstr=request.ServerVariables(Query_String)
If Query_Stringstr<> Then Query_Stringstr=?&Query_Stringstr
IF instr(Server_Name,www.)<1 Then
Response.Status = 301 Moved Permanently
if instr(Path_infostr,index)>0 or instr(Path_infostr,default)>0 Then
Response.AddHeader Location,http://www.&Server_Name
Else
Response.AddHeader Location,http://www.&Server_Name&Path_infostr&Query_Stringstr
End if
Response.End
End if
%>