So I’ve been noticing some strange results in how google peruses our site. One issue is that a url such as this:
http://example.com/randomstring
is showing up on google with all of the data of
http://example.com/
So in my mind there are two solutions. One is to add a 301 redirect whenever someone visits a sub-url of the main one, and redirect them to the parent URL, or just give a 404, with a nice message saying, “Maybe you meant parent-url“.
Thoughts? I’m pretty sure I know where I want to send them, but what is the proper web-etiquette? 404 or 301?
The correct http way would be a 404, as long as a request is made to something that doesn’t exist.
301 is for something that is moved, which is not the case here.
However, 100% correct http convention is rarely followed today. Depending on the context it could be useful to redirect the user to the home page with a notification that the page wasn’t found and that they were redirected. Though in this case you should use a
303 See Othercode.You should never redirect without letting the user know that a redirect happened, though. That confuses the user to think that maybe something is wrong.