redirect 404 to similar urls

前端 未结 6 993
情深已故
情深已故 2021-01-30 11:16

I have a website with stories in it. I can have multiple types of stories within multiple categories like:

  • children
  • romance
  • scifi
  • action
6条回答
  •  半阙折子戏
    2021-01-30 11:33

    Unless you are very sure of the URL the user really wanted to navigate to, using rewrite / redirecting to a specific URL is a very bad idea.

    Taking your example, suppose you want to handle every case where two letters may have been dropped, with 17 characters in the last part of the URL, that's 17*16 = 272 combinations, while it may be possible to match multiple 'false' urls with one regex, you're stil going to need a lot of rewrite rules.

    A better solution would be, to implement 404 handler using PHP (since you included that tag in your q), to generate a list of (say) the top 10 URLs whose paths have the shortest levenstein distance from the requested path, along with a default link and supporting text. (There are mysql based implementations - try Google for URLs). NB handler should still return a 404 status - NB HTML content must be more than a minimum length to suppress MSIE's 'friendly' error message.

提交回复
热议问题