When to show 404 vs 301?

So, I noticed some strange results in the way Google browses our site. One of the problems is that the url is like this:

http://example.com/randomstring

displayed in google with all data

http://example.com/

So in my mind there are two solutions. One of them is to add 301 redirects when someone visits the sub-url of the main one, and redirects them to the parent URL, or simply gives 404 with a good message: "Perhaps you meant the parent URL "

Thoughts? I'm sure I know where I want to send them, but what is proper web etiquette? 404 or 301?

+3
source share
5 answers

The correct http method will be 404 if the request is made for something that does not exist.

301 - , , .

, 100% http . , . 303 See Other.

, , . , , , - .

+8

, , , , : rfc 2616

10.3.2 301

URI URI. Request-URI , , . .

URI Location . HEAD, URI ().

301 , GET HEAD, , , .

. POST     301, HTTP/1.0     GET.

10.4.5 404

, Request-URI. . 410 (Gone) , , , . , , .

, , RFC. , .

+3

, 404 - , , " " ( 301), URL- .

, . Google URL? . domain.com/randomstring, domain.com/index.html? , , 404.

+2

, URL , 301.

0

, ?

301 ( ), , . " ". . - - URL-, 404 ( , ), , -. , , 404. , .

Passing any of these status codes will not stop you from serving "friendly pages" (although 301 usually just redirects you if the browser permits).

Keep in mind that Google doesn't like duplicate content, so you want your site to not display the same content with different URLs.

0
source

Source: https://habr.com/ru/post/1727068/


All Articles