View Full Version : PLEASE HELP WITH 301 REDIRECT!
kevpru
06-26-2007, 05:35 AM
I would like anytime my website is entered without the 'www' (e.g. [website].com) to automatically be redirected to 'http://www.[website].com'. I've been reading alot about this and I cannot seem to put in the correct code. I have opened my default.asp file in WordPad and added the following to the top of the code:
<%@ Language=VBScript %>
<%
' Permanent redirection
Response.Status = '301 Moved Permanently'
Response.AddHeader 'Location', 'http://www.[website].com/'
Response.End
%>
Do I have to edit the file differently instead of simply in WordPad? I have tried using an .htaccess file, which also does not work. I don't think I can use IIS or edit the DNS. Please help, this is frustrating.
vvsharma
06-26-2007, 07:40 AM
You dont need to do anything except have the redirect script within your site's default page.
Something like ,
if (Request.Url.ToString().Contains('website.com'))
{
Response.Status = '301 Moved Permanently';
Response.AddHeader('Location', 'http://www.website.com/');
}
For Reference see: See: http://www.webconfs.com/how-to-redirect-a-webpage.php
Vikram
DiscountASP.NET
www.DiscountASP.NET (http://www.discountasp.net/)
Post Edited (vvsharma) : 6/26/2007 8:36:16 PM GMT
kevpru
06-26-2007, 08:35 AM
Thanks for the reply. The code does not seem to be working. What does the ('/pages') refer to? What page do I put in there?
vvsharma
06-26-2007, 08:37 AM
Oops ,sorry that was just a comment.What seems to to be happening?Put that code in the page load event handler.It worked for me.
Vikram
DiscountASP.NET
www.DiscountASP.NET (http://www.discountasp.net/)
kevpru
06-26-2007, 09:02 AM
Where's the page load event handler? What program should I use to insert the code? Right now it just comes up as text on the website.
vvsharma
06-26-2007, 09:44 AM
Following should be the content of your site's default aspx page (located in the root of your site).
[quote]
<scriptlanguage='C#'runat='server'debug='true'>
protectedvoidPage_Load(objectsender,EventArgse)
{
if(Request.Url.ToString().Contains('website.com'))
{
Response.Status='301MovedPermanently';
Response.AddHeader('Location','http://www.website.com/');
}
}
</script>
<html>
[b]
<formrunat='server'>
</form>
</body>
</html>
</CODE>
Vikram
DiscountASP.NET
www.DiscountASP.NET (http://www.discountasp.net/)
vBulletin® ©Jelsoft Enterprises Ltd.