Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

ASP 301 redirect from index to root

         

asusplay

9:47 pm on May 18, 2006 (gmt 0)

10+ Year Member



Since April one of my sites has been heavily hit and gone into supplemental hell. I realised G was caching the non www version so i fixed that by doing a 301 redirect to the www version of any pages it tries to access in an include file. My site is on shared hosting and does not allow me to access the IIS (asp hosting on windows).

However I have also noticed that it has indexed the homepage (/index.asp) as well as the domain name, so I'm bound to be hit by a duplicate content penalty. After 16 months it makes sense that there isn't just the sandbox at play here. So how can I create a redirect that captures non www versions of pages as well as if it contains "/index.asp" in the path?

I have been playing about with the following code:

if left(hostname,instr(hostname,".")) <> "www." then
response.status = "301 Moved Permanently"
response.addheader "Location", "http://www." & hostname & pathinfo
response.end

elseif left(pathinfo,10) = "/index.asp" then
pathinfo = ""
response.status = "301 Moved Permanently"
response.addheader "Location", "http://" & hostname & pathinfo
response.end

end if

but it just creates and endless loop and I don't know why. Please help, it's driving me crazy!

hvacdirect

4:21 am on May 19, 2006 (gmt 0)

10+ Year Member



Hello,

Here's a script I use on all of my asp pages. My home page is default.asp but you could change it to index.asp. Works for me. I had my host change the IIS settings so it also works on html pages as well.

<%
Dim Page
if Request.ServerVariables("SCRIPT_NAME")= "/default.asp" then
Page="/"
Else
page=Request.ServerVariables("SCRIPT_NAME")
end if

If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.YOURSITE.com" & Page
End if
%>

asusplay

8:03 am on May 19, 2006 (gmt 0)

10+ Year Member



Thanks for this. By looking at your code I thought it would (and should!) work for me, but when I try it I just keep getting an endless loop, as it is redirecting to itself if the filename is /index.asp.

To be honest I don't know what to do reagrding this. I think G has made the lives of ordinary webmasters a misery, as even issues such as this 'cannonicalization' can't seem to be tackled properly, and if you're on shared hosting and you have no access to IIS then you might as well give up . Other SE's don't have a problem or see a difference between domain.com and domain/index.asp, and indeed don't index both and then give a duplicate penalty, but then again they are not as..."complex"...as Google.

hvacdirect

8:28 am on May 19, 2006 (gmt 0)

10+ Year Member



Your right, that doesn't work. I grabbed it from a page I thought I had working, I'll dig around I know I fixed this before in ASP on a shared hosting plane.

asusplay

9:32 am on May 19, 2006 (gmt 0)

10+ Year Member



thanx for this...hope you can find it! i really appreaciate your help :)

sherwoodseo

3:55 pm on May 22, 2006 (gmt 0)

10+ Year Member



FYI - there's a ton of discussion about Google and 301 problems, post-Big-Daddy:

[google.com...]

asusplay

5:16 pm on May 22, 2006 (gmt 0)

10+ Year Member



Thanx. I did read that topic, and it made it clear to me that my sites must have been penalised because of G's inability to handle these canonical issues. No problem on Yahoo or MSN. The bigger Google gets, the more inflexible it becomes and the more of webmasters time it wastes trying to deal with these stupid issues.

I still don't know how to redirect my www.mydomain.com/index.asp pages to just www.mydomain.com/

It just creates an endless loop and i have no access to the IIS.

So i was just wondering whether anyone had some clever fix....

TearingHairOut

10:28 pm on May 22, 2006 (gmt 0)

10+ Year Member



I found a fairly comprehensive list of options <on an SEO website>

I am in a similar situation to asusplay with IIS etc.

Many shared IIS hosts support php, so the php option given on <that site> might work.

The code for a general redirect that they give is:

<?php
if (substr($_SERVER['HTTP_HOST'],0,3)!= 'www') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ['.$_SERVER['HTTP_HOST']...]
.$_SERVER['REQUEST_URI']);
}
?>

However, they don't say what file name it should be placed in. I don't want to hijack the thread, but if this solution were to work for me, it might work for asusplay and other people on shared IIS.

Can anyone say what the file should be called?

<See Forum Charter [webmasterworld.com]>

[edited by: tedster at 11:16 pm (utc) on May 22, 2006]