Results 1 to 3 of 3

Thread: URL redirect

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    LA
    Posts
    57

    Question URL redirect

    Hello,

    I have questing about redirect. My company ask me to make redirect for the corporate website from “Domain.com” to “www.domain.com”
    I was able to do this with the code bellow.

    Code:
    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) 
       ' Fires at the beginning of each request 
       Dim strRedirectToWWW As String 
       Dim bAdminURl As Boolean = False 
    
       strRedirectToWWW = ConfigurationSettings.AppSettings("RedirectToWWW") 
    
       'For testing set RedirectToWWW to false 
       If strRedirectToWWW.Trim.ToLower = "true" Then 
    
           Dim sOldPath As String = Request.Url.ToString.Trim.ToLower 
           Dim sNewPath As String = "" 
    
           If sOldPath.IndexOf("www.") = -1 Then 
           		sNewPath = sOldPath.Replace("Domain.com", "www.Domain.com") 
    
    		Response.AddHeader("Location", sNewPath) 
    		Response.RedirectLocation = sNewPath 
    		Response.Status = "301 Moved Permanently" 
    		Response.StatusCode = 301 
    		Response.Redirect(sNewPath) 
    	End If	
        End If 
    
    End Sub
    Here is my question:
    When I redirect website “http://Domain.com” to “http://www.Domain.com” the end result looks like this “http:// www.Domain.com/index.aspx”.
    I there a way to remove “Index.apsx” form URL during redirect?
    I want my end result from redirection look like this “http://www.Domain.com/”

    Thank you.

    P.S. I'm using .NET Framework 1.1

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: URL redirect

    Well, to start with, you're redirecting wrong. Response.Redirect does a 302, so no matter what you put in the header, that line will make it a 302 rather than a 301 as you wanted. All you really need is

    Code:
    Response.Status = "301 Moved Permanently"
    Resopnse.AddHeader("Location", sNewPath)
    Second, what happens when you go to www.domain.com directly? If it appends the index.aspx then it'd an IIS configuration issue, wouldn't it?

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    LA
    Posts
    57

    Re: URL redirect

    Thank you for your response mendhak

    You wore right Response.Redirect was doing 302 Temporary redirect.

    When I implemented your code it worked like a charm.

    However it’s still redirects to “http:// www.Domain.com/index.aspx”.

    To answer your question:
    Second, what happens when you go to www.domain.com directly?
    When I go to www.domain.com this is the result I get “http://www.domain.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width