Saturday, October 01, 2005

What do you do if your host doesn't support Mod Rewrite?

Use a custom 404 error page! My host GoDaddy doesn't support Mod Rewrite, but they do support custom 404 pages, so when I wanted to redirect my site feed, I wrote the following PHP script to handle 404 page not found responses:
<?
// get the requested URI.
$uri = $_SERVER['REQUEST_URI'];

// if the URI starts with my old feed path...
if (strpos($uri, "/roller/rss/crazybob") === 0) {
  // redirect to the FeedBurner feed.
  header("Location: http://feeds.feedburner.com/crazybob/");
  exit;
}

// redirect to the home page.
header("Location: /");
?>
When the user requests /roller/rss/crazybob, this script redirects them to my FeedBurner feed. For any other missing path, the script redirects them to my home page. You could easily build up a robust rewriting facility around this. Update: I fixed some escaping on the code example and rewrote this entry to make it clearer.

1 Comments:

Anonymous Anonymous said...

This comment has been removed by a blog administrator.

12:13 PM  

Post a Comment

<< Home