rrhandle8
asked on
ASP.NET SEO Redirect
I need to write a SEO redirect for my site.
The live site is www.ticketstoregame.com
The staging site is www.ticketstoregame.net
Their are build sites for both on my pc.
I do not want to write separate global.asxa pages for each site. Just one that will handle all the possibilities.
You can see in the attached sub from the global.asxa file, I am tyring to prevent the redirect when I am on the .net site, but it redirects me to the .com site.
What am I doing wrong?
Protected Sub Application_BeginRequest(B yVal sender As [Object], ByVal e As EventArgs)
'Declare the server URL ex:www.mysite.com
Dim server As String = Request.ServerVariables("S ERVER_NAME ")
If server.Contains(".net") Then
'Don't do anything
Else
'Declare the form being accessed ex: Default.aspx
Dim url As String = Request.ServerVariables("U RL")
' Declare the query string in the URL
Dim querystring As String = Request.ServerVariables("Q UERY_STRIN G")
' Merge the server name with the form ex: www.mysite.com/Default.aspx
Dim fullurl As String = server & url
' Create a string for any URL with a querystring ex: ?&categoryid=1
Dim tail As String = "?" & querystring
' Declare string you want replaced ex: www.
Dim patternwww As String = "www."
' Declare what you want it replaced with
Dim patternclear As String = String.Empty
' Create an if statement for URL's containing the string you dont want and containg query strings.
If fullurl.Contains(patternww w) And querystring <> Nothing Then
' Replace www. with nothing
Dim wwwrpl As String = fullurl.Replace(patternwww , patternclear)
' Build a string for the final URL
Dim targeturl As String = "http://" & wwwrpl & tail
' Create the 301 Redirect
Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Locati on", targeturl)
Response.[End]()
End If
' Create an if statement for URL's containing the string you don't and don't contain query strings
If fullurl.Contains(patternww w) And querystring = Nothing Then
' Replace www. with nothing
Dim wwwrpl As String = fullurl.Replace(patternwww , patternclear)
' Build a string for the final URL
Dim targeturl As String = "http://" & wwwrpl
' Create the 301 Redirect
Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Locati on", targeturl)
Response.[End]()
End If
End Sub
The live site is www.ticketstoregame.com
The staging site is www.ticketstoregame.net
Their are build sites for both on my pc.
I do not want to write separate global.asxa pages for each site. Just one that will handle all the possibilities.
You can see in the attached sub from the global.asxa file, I am tyring to prevent the redirect when I am on the .net site, but it redirects me to the .com site.
What am I doing wrong?
Protected Sub Application_BeginRequest(B
'Declare the server URL ex:www.mysite.com
Dim server As String = Request.ServerVariables("S
If server.Contains(".net") Then
'Don't do anything
Else
'Declare the form being accessed ex: Default.aspx
Dim url As String = Request.ServerVariables("U
' Declare the query string in the URL
Dim querystring As String = Request.ServerVariables("Q
' Merge the server name with the form ex: www.mysite.com/Default.aspx
Dim fullurl As String = server & url
' Create a string for any URL with a querystring ex: ?&categoryid=1
Dim tail As String = "?" & querystring
' Declare string you want replaced ex: www.
Dim patternwww As String = "www."
' Declare what you want it replaced with
Dim patternclear As String = String.Empty
' Create an if statement for URL's containing the string you dont want and containg query strings.
If fullurl.Contains(patternww
' Replace www. with nothing
Dim wwwrpl As String = fullurl.Replace(patternwww
' Build a string for the final URL
Dim targeturl As String = "http://" & wwwrpl & tail
' Create the 301 Redirect
Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Locati
Response.[End]()
End If
' Create an if statement for URL's containing the string you don't and don't contain query strings
If fullurl.Contains(patternww
' Replace www. with nothing
Dim wwwrpl As String = fullurl.Replace(patternwww
' Build a string for the final URL
Dim targeturl As String = "http://" & wwwrpl
' Create the 301 Redirect
Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Locati
Response.[End]()
End If
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER