strategesim
strategesim

Reputation: 326

Redirect to a page even with typing error

I am looking for a solution that would allow a redirection when one character in the URL path is missing.

The example below is simple, but in my case I have URL with longer paths and sometimes complicated to write. I want to find a solution to handle typing errors, I mean still redirect when they happen.

Example:

I know about apache redirection, and already tried something like :

RewriteRule ^helo$              hello.php
RewriteRule ^hell$              hello.php
RewriteRule ^ello$              hello.php
RewriteRule ^hllo$              hello.php
RewriteRule ^hello$             hello.php

But I would like something automatic, for cases that I didn't note, such as /hell...

The best would be to do that with regexp in apache, but I'm quite bad in apache htaccess management.

I thought also I could do that in my 404 page, with some JS code, and redirect if the page url is one character far from elements on a list.

So what do you think ? Would there be a simpler solution than that horrible JS redirect ?

Upvotes: 1

Views: 73

Answers (1)

dgn
dgn

Reputation: 1223

Do you have a limited set of known URLs to serve? Then you could maybe calculate the edit distance with those when you hit a 404, return the closest with a threshold to avoid ridiculous matches?

Upvotes: 1

Related Questions