Topic: 404 redirect possible?

Hi guys,

I'm trying to set up PunBB on my desktop modding site guimods.com. You can find the forum here.

I used to have a VB powered forum before but I didn't want to renew my license as I didn't like how it had become so bloated. However, since I've had the forum for almost two years and it was attracting quite a lot of search engine traffic, the problem is that when a user lands on an invalid link of a previous forum post, PunBB doesn't generate a 404 page or direct the user to the forum homepage. It only prints "Bad request" on a blank page, so the users have no choice but to return to the search page and click on some other link.

So I am losing all my traffic that lands on a dead link in the forum directory. Is there a way to redirect such requests to forum homepage?

Click here to see the error in action.

Re: 404 redirect possible?

I put a hook in rewrite.php specifically because I anticipated people would want more control over their 404s. smile

Re: 404 redirect possible?

Sorry, I've no idea how to utilize this 'hook'. Can you please explain what do I need to insert in rewrite.php to redirect 404's to forum index?

Re: 404 redirect possible?

You should create an extension for that. There are plenty of extensions already floating about that you can use as exampe.

5 (edited by Kyle 2008-03-05 23:28)

Re: 404 redirect possible?

Wouldn't this be easier by just putting some rewrite rules in htaccess rather than writing a whole plugin? Plus it should be a 301 redirect and not send any 404.

For example, some stuff to get started with redirecting phpbb to punbb (you need more rules for profiles etc):

RewriteEngine on
RewriteBase /forum #change this to your forum folder

RewriteCond %{QUERY_STRING} f=([0-9]*) [NC]
RewriteRule viewforum\.php viewforum\.php?id=%1 [R=301,L,NC]

RewriteCond %{QUERY_STRING} t=([0-9]*) [NC]
RewriteRule viewtopic\.php viewtopic\.php?id=%1 [R=301,L,NC]

Eventually search engines will follow the 301 redirects and update their search results as well, so you don't lose any pagerank or whatever it is these days.

EDIT: Here's some to get started with VB and maybe more examples will help you understand how it works as well:

RewriteEngine on
RewriteBase /forum #change this to your forum folder

RewriteCond %{QUERY_STRING} showforum=([0-9]*) [NC]
RewriteRule index\.php viewforum\.php?id=%1 [R=301,L,NC]

RewriteCond %{QUERY_STRING} showtopic=([0-9]*) [NC]
RewriteRule index\.php viewtopic\.php?id=%1 [R=301,L,NC]

Re: 404 redirect possible?

Kyle: Good point

Re: 404 redirect possible?

Why doesn't it generate a decent error page like this?

Kyle, thanks for your help. I'll try it out.

Re: 404 redirect possible?

I was originally torn between generating a full-blown custom 404 page and doing what PunBB does now. We did it this way for the sake of simplicity with the idea that anyone who wants a custom 404 page can make one via the extension system.

And that link you sent me to just shows the text "Page not found"

Re: 404 redirect possible?

Smartys, sure it's simpler but you shouldn't expect everyone to know how to create extensions.

Well, anyways, I'm back to VB.

Re: 404 redirect possible?

Homeboy: No, but I don't expect people to be using a piece of beta software on a production server either. tongue
When the final version is released, I fully expect someone will have coded an extension to generate a full-blown 404 page. Meanwhile, you shouldn't expect beta software to be as fully supported as the stable version, for obvious reasons wink

11

Re: 404 redirect possible?

Homeboy wrote:

Smartys, sure it's simpler but you shouldn't expect everyone to know how to create extensions.

Smartys wrote:

When the final version is released, I fully expect someone will have coded an extension to generate a full-blown 404 page.
Meanwhile, you shouldn't expect beta software to be as fully supported as the stable version, for obvious reasons

Ur both right.. lol
Smartys, how could Homeboy code an extension if he doesn't know HOW to do it ?
Mean, it would be a GOOD IDEA (imo) to release the doc on extensions asap (i know the doc is often pushed last on the planning), even in a basic form.

Re: 404 redirect possible?

Mpok: Nobody said he had to. He asked if there was a way to redirect the traffic. I said yes, I specifically added a hook so that people could write extensions to do what they want with 404 traffic.
And I don't know that it's necessarily a good idea to spend time working on documentation for writing extensions when we could be working on the code instead. Especially when a system for evaluating, searching, storing, etc extensions isn't in place.

Re: 404 redirect possible?

As long as vanilla Pun 1.3 send a proper 404 to the web server, any admin can direct that web server to generate whatever 404 page he wants.