Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
How to Avoid 404s and Redirect Old URLs in PHP
Aug 03, 2010 @ 19:15:27

On the SitePoint PHP blog today there's a new post showing you how to create a 404 page that will redirect people back to the page they're looking for (that used to be there).

It's often necessary to reorganize your site and change the URL structure but, assuming you have similar content, users should rarely encounter a "page not found" error. Producing unnecessary 404 pages is one of my top 10 development mistakes. In this article, we'll create an automated PHP redirection system that converts old URLs to a new address. It's not production code, but it will illustrate the basics so that you can adapt it for your own website.

They walk you through the creation of a 404 error handling PHP page, configuring your server to use it and making the mapping of new URL to old URL. There's even a bit to include if there's not a mapping for a requested page - returning a 301 HTTP header.

tagged: 404 redirect map url tutorial

Link:

php|architect:
Bing Powered 404 for non-WordPress websites
Jun 17, 2010 @ 14:10:29

Following up on his Bing 404 plugin for WordPress article, Cal Evans has put together an example for those not using WordPress to accomplish the same thing.

I had several people tell me that while they liked the idea, they didn't want to install WordPress just so they can have intelligent 404 errors. Several other people pinged me and suggested a way that you could use the Bing Search API to handle 404's without WordPress. As a public service, I am going to try and bridge the gap between these two groups. Going on leads provided by friends, I have hammered out a solution that works with Apache and PHP.

The solution uses a custom 404 page (as set in Apache) that pulls in the "top ten" links from the current site as reported back by the Bing.com search engine. With the help of the API making a request and getting back an object to loop through is simple. This could easily be adapted to accept terms based on the content page that they were trying to find or some keywords based on your site's content.

tagged: bing wordpress search 404 error apache tutorial

Link:

NETTUTS.com:
404/403 Website Error Pages With PHP Auto-Mailer
Apr 20, 2009 @ 12:57:14

NETTUTS.com has posted this new tutorial you can use to monitor when and what pages people are trying to get to on your site that aren't found:

Although many web developers rely on server logs to keep an eye out for hits on error pages, I'm going to take a different approach by using a PHP generated email. In addition, we will spice up the design a bit, add basic navigation and link to the website sitemap.

He briefly explains what error (404/403) pages are and how they work before getting into the mailing portion - a script that, using the phpMailer tool, notifies you when people hit the 404/403 page and includes things like their IP, where they came from and what the requested page was.

tagged: email automailer page message error website 403 404

Link:

Mark Kimsal's Blog:
Is Your MVC MIA When it Comes to 404s?
Jul 08, 2008 @ 12:51:20

In a new post to his blog, Michael Kimsal points out a post from his brother (Mark) that wonders if your framework handles 404 errors the best/most useful way it can.

This post is about the consistency of frameworks. Consistency is key to a low learning curve. [...] Yesterday, my brother asked me how he could capture 404 errors in Cognifty, as he was building an app that relied on dealing with random URL patterns. [...] After talking for a bit, we decided that handing off the request to a standard service (or controller) was the best way to handle this type of "error". He started searching to see if other frameworks had a consistent, or at least documented, way of dealing with missing controllers.

In his research he found one framework - the Zend Framework - that handed them by default as an error and passed them off to that handler. Mark notes that, depending on your frame of reference, this may or may not be considered a true error.

His Cognifty framework handles things a bit differently. It allows you to change the presentation handler to redirect to another url if an error like a 404 is thrown - a technically "more correct" way of handling things.

tagged: mia 404 error framework zendframework cognify handle redirect

Link:

Matthew Turland's Blog:
Interesting Bug in the HTTP Streams Wrapper
Apr 14, 2008 @ 13:49:04

Matthew Turland has come across an "interesting bug" in PHP's stream wrappers functionality - some strange 404 or 500 HTTP errors in one of his scripts.

I wrote a small script a while back that's gained a surprising amount of popularity thanks to a plug from the site that it posts to. [...] I learned that this [connection from the script] could be done with streams, I attempted to implement it in that fashion, but ran into strange issues where I would get 404 or 500-level HTTP errors rather than the response I was expected.

He eventually found the bug related to his problem (in the 5.2.x branch) but happily notes that it has been corrected and will be patched in the upcoming 5.3 (and 6) branches.

tagged: bug streams wrapper issue 404 500 connection header contenttype

Link:

Richard Miller's Blog:
UPHPU meeting on custom 404 pages
Feb 22, 2006 @ 12:49:49

From Richard Miller's blog today, there's a new post with content from the Utah PHP Users Group meeting that's just passed (Feb. 2006) on the topic of custom 404 pages.

When you try to visit a web page that doesn't exist, the server usually returns a 404 error message - "Page Not Found". At the Utah PHP Users group meeting last Thursday, Mac Newbold presented on custom 404 pages. Custom 404 pages can help maintain your website branding, help you fix broken links, and help your users find something useful when they don't find what they're looking for.

Custom 404 pages are even more powerful when you combine them with PHP. I certainly didn't expect the flood of ideas that Mac presented for using custom 404 pages.

Among the suggestions of things to do with the error pages are things like: sending an email when someone gets a 404, search the site for something similar, use it as a redirect for old to new URLs, and more.

tagged: user group utah meeting february 2006 custom 404 pages user group utah meeting february 2006 custom 404 pages

Link:

Richard Miller's Blog:
UPHPU meeting on custom 404 pages
Feb 22, 2006 @ 12:49:49

From Richard Miller's blog today, there's a new post with content from the Utah PHP Users Group meeting that's just passed (Feb. 2006) on the topic of custom 404 pages.

When you try to visit a web page that doesn't exist, the server usually returns a 404 error message - "Page Not Found". At the Utah PHP Users group meeting last Thursday, Mac Newbold presented on custom 404 pages. Custom 404 pages can help maintain your website branding, help you fix broken links, and help your users find something useful when they don't find what they're looking for.

Custom 404 pages are even more powerful when you combine them with PHP. I certainly didn't expect the flood of ideas that Mac presented for using custom 404 pages.

Among the suggestions of things to do with the error pages are things like: sending an email when someone gets a 404, search the site for something similar, use it as a redirect for old to new URLs, and more.

tagged: user group utah meeting february 2006 custom 404 pages user group utah meeting february 2006 custom 404 pages

Link:

Utah PHP Users Group - February Meeting, 02.16.06 @ 7pm
Feb 16, 2006 @ 12:37:15

For the February 2006 meeting, they Utah PHP Users Group will be talking about Apache 404 handler scripts created in PHP.

Mac Newbold will present on PHP 404 handler scripts. Running PHP with Apache has some definite advantages. One that I use frequently is using a PHP script as the 404 document that apache uses when a page can't be found. You can use it for many things. PHP.net uses it to run a site search, to try and find the page you were looking for. You can use it to create "virtual" URLs, where one script handles requests for many different URLs and hands back dynamic content based on the page name. You can even combine it with things like GD to make dynamic images that are created on the fly for each URL.

The meeting is happening on the 16th at 7pm MST at the Linux Networx offices. You can RSVP and get a map to the location from their site...

tagged: utah users group apache 404 script 16th 7pm utah users group apache 404 script 16th 7pm

Link:

Utah PHP Users Group - February Meeting, 02.16.06 @ 7pm
Feb 16, 2006 @ 12:37:15

For the February 2006 meeting, they Utah PHP Users Group will be talking about Apache 404 handler scripts created in PHP.

Mac Newbold will present on PHP 404 handler scripts. Running PHP with Apache has some definite advantages. One that I use frequently is using a PHP script as the 404 document that apache uses when a page can't be found. You can use it for many things. PHP.net uses it to run a site search, to try and find the page you were looking for. You can use it to create "virtual" URLs, where one script handles requests for many different URLs and hands back dynamic content based on the page name. You can even combine it with things like GD to make dynamic images that are created on the fly for each URL.

The meeting is happening on the 16th at 7pm MST at the Linux Networx offices. You can RSVP and get a map to the location from their site...

tagged: utah users group apache 404 script 16th 7pm utah users group apache 404 script 16th 7pm

Link:


Trending Topics: