Forum Moderators: open

Message Too Old, No Replies

ASP Redirect - for mal formed urls

Redirecting working for non www to www but another pops up

         

watercrazed

8:09 pm on Mar 4, 2006 (gmt 0)

10+ Year Member



Hi,
I have some code at the top of each page that redirects non-www to www, checked that with a couple of header status checkers and it works. But I now have a problem with an www.mydomain.com//page.htm showing up in googles index instead of www.mydomain.com/page.htm.

I am not an ASP programer so I am a little concerned that maybe the code doing the non-www to www redirect I was provided with is causing the problem.

Here is the code

<%
dim hostname
dim pathinfo
dim bRedirect
dim MainDomain

hostname = request.servervariables("HTTP_HOST")
pathinfo = request.servervariables("PATH_INFO")
MainDomain = "www.mydomain.com"
if pathinfo <> "" then
if instr(lcase(pathinfo),"default.asp") > 0 or instr(lcase(pathinfo),"index.asp") > 0 or instr(lcase(pathinfo),"index.aspx") > 0 then
MainDomain = MainDomain &"/" & mid(pathinfo,2,instrrev(pathinfo,"/")-1)
else
MainDomain = MainDomain & pathinfo
end if
else
MainDomain = MainDomain & "/"
end if
if left(hostname,instr(hostname,".")) <> "www." then bRedirect = true

if instr(lcase(hostname),"default.asp") > 0 or instr(lcase(hostname),"index.asp") > 0 or instr(lcase(hostname),"index.aspx") > 0 then bRedirect = true

if bRedirect then
response.status = "301 Moved Permanently"
response.addheader "Location", "http://" & MainDomain
response.end
end if
%>

Anyone see something that may be causing the www.mydomain.com//page.htm problem? or have an idea how I can add a redirect that would redirect www and non www www.mydomain.com//page.htm to www.mydomain.com/page.htm throughout the site.

ItzFX

1:46 am on Mar 10, 2006 (gmt 0)

10+ Year Member



My guess is that you need to make the following change:

Change Line 12 (MainDomain = MainDomain &"/" & mid(pathinfo,2,instrrev(pathinfo,"/")-1) )
To:
MainDomain = MainDomain & mid(pathinfo,2,instrrev(pathinfo,"/")-1)
^just got rid of the "/" in there