WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • General Community »
  • Global WebsiteBaker 2.8.x discussion »
  • Redirecting 404 error to a search of missing page name
  • Print
Pages: [1]   Go Down

Author Topic: Redirecting 404 error to a search of missing page name  (Read 20711 times)

Offline fsuk

  • Posts: 127
Redirecting 404 error to a search of missing page name
« on: June 10, 2008, 03:39:51 PM »
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)

Code: [Select]
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:
Code: [Select]
$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:

   
Code: [Select]
   
    $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.
« Last Edit: June 10, 2008, 03:41:30 PM by fsuk »
Logged
You say deviant like its a bad thing...

Argos

  • Guest
Re: Redirecting 404 error to a search of missing page name
« Reply #1 on: August 16, 2008, 06:24:42 PM »
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.
Logged

Offline fsuk

  • Posts: 127
Re: Redirecting 404 error to a search of missing page name
« Reply #2 on: August 17, 2008, 12:43:25 AM »
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.
Logged
You say deviant like its a bad thing...

iggyFlames

  • Guest
Re: Redirecting 404 error to a search of missing page name
« Reply #3 on: August 17, 2008, 01:45:20 AM »
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
Logged

Offline fsuk

  • Posts: 127
Re: Redirecting 404 error to a search of missing page name
« Reply #4 on: August 17, 2008, 06:51:01 PM »
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.
Logged
You say deviant like its a bad thing...

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Redirecting 404 error to a search of missing page name
« Reply #5 on: August 17, 2008, 08:16:03 PM »
Have a look here as well: http://help.WebsiteBaker.org/pages/en/knowledge-base/custom-error-pages.php

cheers

Klaus
Logged

Offline fsuk

  • Posts: 127
Re: Redirecting 404 error to a search of missing page name
« Reply #6 on: August 18, 2008, 01:25:14 PM »
Well it would seem that they are already planning to do this in WB3, i think ill just work on moding wb2.7
Logged
You say deviant like its a bad thing...

Offline fsuk

  • Posts: 127
Re: Redirecting 404 error to a search of missing page name
« Reply #7 on: August 18, 2008, 03:17:26 PM »
This idea has been named wbx2.7. New thread: https://forum.WebsiteBaker.org/index.php/topic,10745.0.html
Logged
You say deviant like its a bad thing...

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • General Community »
  • Global WebsiteBaker 2.8.x discussion »
  • Redirecting 404 error to a search of missing page name
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2