Redirecting 404 error to a search of missing page name

fsuk

You say deviant like its a bad thing...

fsuk

Well it would seem that they are already planning to do this in WB3, i think ill just work on moding wb2.7
You say deviant like its a bad thing...


fsuk

So far ive managed to get it working with the first level of menus ie not sub menus, after ive got the working i have to check that things like news posts will still work, stop wb creating the php filess and then add a settings option to turn it on an off.

I've got a lot of free time this week so it should progress quickly.
You say deviant like its a bad thing...

iggyFlames

Thanks for share! I think it could be useful in cases when user keep the page address in "Favorites", hu?

Quote from: fsuk on August 17, 2008, 12:43:25 AM
I currently working on using something similar to this to modify wb so that it dosn't need physical pages in the pages folder by redirecting the user to a dummy page and then matching the page typed with the page link in the database to then retrive the data of the page. I should have this mod finished by the end of the week.

Oh, I'm very interested in this work. Would you tell us if you have success?

Regards,

Iggy

fsuk

It would come in use for instance if the link was broken, say the page had been move, renamed or deleted.

I currently working on using something similar to this to modify wb so that it dosn't need physical pages in the pages folder by redirecting the user to a dummy page and then matching the page typed with the page link in the database to then retrive the data of the page. I should have this mod finished by the end of the week.
You say deviant like its a bad thing...

Argos

Quote from: fsuk on June 10, 2008, 03:39:51 PM
So for example: A user types the address http://www.mysite.com/blue-flamingo.php but the page dosn't exist so the user is redirected to a search page of any of the words blue flamingo. Because your site has a page named pink flamingo it shows up in the search results.

When would a user type the URL of a page on your site that doesn't exist? People follow links to navigate, they don't type URL's to visit another page, or do they? I don't see a real world use of your idea. It's cleverly made up though.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

fsuk

I haven't been using WB long but i've already made a few modifications to my sites WB.

One i've made is to redirect 404 errors (page not found) to the wb search using the name of the file not found as the search term.

For this you need to have mod_rewrite enabled on your server. (google for more info)

1. Add to your .htaccess file (see here for info on .htaccess http://www.javascriptkit.com/howto/htaccess.shtml)

RewriteEngine on

#404 redirects
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/\.]+).php$ /search/index.php?string=$1&match=any&error=404 [L]


2. In search/search.php after $string = preg_replace("/(^|\s+)([-=+_&!;#]|\\\\\"|\\\\')+(?=\s+|$)/", " ", $string); on a new line add:
$string = str_replace("-", " ", $string );

3. In search/search.php after // Show search header (aprox line 154) but before echo $search_header; on a new line add:

   
   
   $error = 'none';
   if(isset($_REQUEST['error'])){
       $error = $_REQUEST['error'];
   }
        if($error == '404'){
       echo '404 Error. The page you entered was not found. <br>Please check the search results below to locate the page you are looking for.';

   }




OK what does this do? Well:
1: This checks to see if the requested page or dir exists if not then it goes to the search page using the name of the file or dir minus the .php as the search term in an any word search and adds &error=404 onto the address

2: Because the default page seperator is '-' and if you have pages named a-page.php then the it will search for 'a-page' which probably wont return anything. This replaces the '-' with a ' ' so you search for 'a page'

3: As you can see in 1 i've added a &error=404 to the address in the .htaccess file. This bit checks the address for an error code and if the error code = 404 then it adds a message to the top of the search page.

So for example: A user types the address http://www.mysite.com/blue-flamingo.php but the page dosn't exist so the user is redirected to a search page of any of the words blue flamingo. Because your site has a page named pink flamingo it shows up in the search results..

As far as i can tell it dos'nt affect the normal search or any thing else.
You say deviant like its a bad thing...