404.asp + 301 redirect
worldofrugs | Posted 8:39am 4. June 2008 Server Time |
Hi all,
Hopefully someone can help me here as I'm not an asp guru :)
I'm trying to create a custom 404.asp page that looks if some files have been moved (301-permanent) and redirects it to there, or else shows my 404.asp code..
Example:
- User requests /123.html
- /123.html has become /sub/456.asp
- User is redirected to /sub/456.asp and header responds 301
(letting search engine know it has been moved permanent)
- User requests /abc.html
- /abc.html does not exist
- Header responds 404 and display my original ASP code
(I have a custom 404.asp already in place, therefore like to display the original code if it does responds 404)
Anyone has any ideas on this or (even better) some code that might help me out?
Thanks all!
p.s.: I know it would be much more simple to do this on the server side, but my host (GoDaddy - windows/shared hosting) won't let me change much settings, an they're not willing to help me on this. |
katy8439 | Posted 10:10am 4. June 2008 Server Time |
<%
IF Request.ServerVariables("SCRIPT_NAME") = "/123.html" THEN
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/sub/456.asp"
response.end
END IF
%>
You'll need to do this for each URL, or map them at some point e.g.
RequestedPage = Request.ServerVariables("SCRIPT_NAME")
IF RequestedPage = "/123.html" THEN
NewPage = "456.asp"
ELSEIF RequestedPage = "ABC" THEn
NewPage = "DEF"
END IF
ETC
You can then redirect to the NewPage
Hope that helps!
Katy
worldofrugs | Posted 10:29am 4. June 2008 Server Time |
Thanks for the reply Katy,
This will help me on my way (I hope)....
In your example:
<%
IF Request.ServerVariables("SCRIPT_NAME") = "/123.html" THEN
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/sub/456.asp"
response.end
END IF
%>
Can I do this?:
<%
IF Request.ServerVariables("SCRIPT_NAME") = "/123.html" THEN
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/sub/456.asp"
response.end
ELSE
Response.Status = 404
<% My ASP Code %>
END IF
%>
Appreciate you help so much!
worldofrugs | Posted 10:35am 4. June 2008 Server Time |
One more thing...
I just copied and pasted your script and only adjusted the file names/path...
It does not redirect and has a header 200-OK instead of 301..
Did I misunderstood something? (example: "SCRIPT_NAME", not sure what this is / what to do with that)...
Sorry for my dumb being and thank you for your patience ;)
katy8439 | Posted 2:30am 5. June 2008 Server Time |
Whoops, my bad! I'd copied the code from something else I did.
SCRIPT_NAME grabs the name of the page you're currently on - which won't work for you as you'll be one the 404 page - silly me.
I think you need to figure out the requested page using Request.ServerVariables("HTTP_REFERER") That should give you the name of the page that the user requested before they were redirected to the 404 page.
In regards to your other question, yes you can do:
IF Blah Then
Redirect
ELSEIF Blah
Redirect
ELSE
404
END IF
:)
iamarrow | Posted 0:52am 29. June 2008 Server Time |
hello you might want to treat 404's and 301's status(es)separately/differently
Response.Status = "404 Not Found" 'for 404
Response.Status = "301 Moved Permanently" 'for 301
http://gsitecrawler.com/articles/error-404-200.asp
Reply to Post 404.asp + 301 redirect
|
|
|