301 or 307 redirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

301 or 307 redirect

Post by alex.barylski »

I have a situation where I test for the validity of a session ID and on failure I would redirect to a error page. Should I use status code 301 (permenant) or 307(temporary)?

Remember search engines will never see this content, because you must be authenticated first, however, the document has not truly moved, it's only just unavailable to un-authenticated user agents.

What says you?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: 301 or 307 redirect

Post by requinix »

Shouldn't you be using a 403 instead?

(Tip: redirects can happen for any status code, not just the 3xx range.)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: 301 or 307 redirect

Post by alex.barylski »

Interesting, cause I was just thinking 401 Not authorized ?

http://www.checkupdown.com/status/E403.html
If the entire Web site is actually secured in some way (is not open at all to casual Internet users), then an 401 - Not authorized message could be expected. It is possible, but unlikely, that the Web server issues an 403 message instead.
Not the entire web site though, so maybe a 403 is more appropriate?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: 301 or 307 redirect

Post by requinix »

It's kind of a fuzzy line, but I'd say 401 is to block anonymous users and 403 is for an authenticated user who's not allowed (which implies that their current authentication allows them access to other areas).

Point is, you can redirect for a 4xx code too.
Post Reply