How many redirects is too many?
March 30, 2007 2:23 PM   Subscribe

.htaccess question -- how many redirects is too many?

I'm in the process of updating a magazine site, and changing the CMS while I'm at it.

I can't recreate the URL structure the old CMS used, so I think I need to "manually" redirect people from the old URLs to the new ones.

Creating the list isn't a problem, I can automate that. But I'm talking about 1000 addresses here. Is that too many to put into an .htaccess file and not experience a performace hit?

Also, is there a best redirect method to use to ease Google through the transition?
posted by crickets to Computers & Internet (12 answers total) 2 users marked this as a favorite
 
Response by poster: In case anyone has any bright ideas, I'm going from this URL structure:

../year/month/truncated-article-title.php

... to:

../news/full-article-title/
posted by crickets at 2:24 PM on March 30, 2007


Can you do a regex match instead? Maybe regex it, send it through some lookup page that gets the full title from the article title, and then redirects them,
posted by xmutex at 2:38 PM on March 30, 2007


Response by poster: I don't think I can because the first system truncates the title as used in thte URL, and the new system doesn't. I could be wrong.

I will be using some regex to swap out [year/month/] for [news/].
posted by crickets at 2:41 PM on March 30, 2007


Look at the RewriteMap directive for mod_rewrite. It's made for this, and uses an external mapping file.
posted by smackfu at 3:11 PM on March 30, 2007


1000 may be a bit much given .htaccess is reparsed each request, though it depends on how busy you are and how beefy your server is. Shoving it in httpd.conf/vhost.conf would be less of an issue.

A better solution is probably to rewrite the whole of /year/month/ to a PHP script which does the mapping (assuming you've got some sort of bytecode cache enabled for that, otherwise it too will be reparsing each request (grr!)).
posted by Freaky at 3:14 PM on March 30, 2007


xmutex has the right idea, as does smackfu.

For google friendliness, make the redirects 301 (permanent.)
posted by davejay at 6:12 PM on March 30, 2007


You know what? Forget my previous comment. Here's what I recommend:

First, read http://www.seobook.com/archives/000297.shtml.

Now, consider: you have the /year/month/ directory tree completely deprecated, right? So set up that directory tree with no files in it, except for an .htaccess file at each level of /year/month/. Each of those .htaccess files should have a 301 redirect from each individual article's old name to the new article.

The bad part of this: it's a lot of work to set up, although shell scripts can automate most of the heavy lifting.

The good part of this: once you're done, you're DONE, because no more articles will be added to the legacy directory tree. Also, each request for an old page will only result in the parsing of a much, much smaller .htaccess file than if you collected all of the article redirects (for all years/months) in one place. And people hitting the new page wouldn't trigger a parsing of those .htaccess files at all.
posted by davejay at 6:18 PM on March 30, 2007


PS: as mentioned in the linked article, very spider-friendly.
posted by davejay at 6:19 PM on March 30, 2007


Here's how I would do it.

Use mod_rewrite to set up a rule so that "../year/month/truncated-article-title.php"

points to something like this

../year/month/redirect.php?trunc_title="truncated-article-title"

I'm assuming that all these magazine articles are in some sort of database (mysql?). If so, search (inside redirect.php) for the truncated title in the title field, retrieve full title, and set Location to

"../news/full-article-title/"

Everything that happens in redirect.php will be transparent and quick (at least faster than a 1000 redirect statements in .htacess) so the end user wouldn't even notice.

PS: Here's my .htaccess to do this


php_value register_globals on
RewriteEngine on
RewriteRule ^([^/\.]+)/$ index.php?id=$1 [L]
RewriteRule ^([^/\.]+)$ index.php?id=$1 [L]


see this tutorial for more info.
posted by special-k at 8:34 PM on March 30, 2007


PS: ignore the /year/month in my third line.

just redirect.php?... would be fine.
posted by special-k at 8:37 PM on March 30, 2007


oy. I meant to say fourth line
posted by special-k at 8:38 PM on March 30, 2007


Ya this is kind of confusing what you want to accomplish..

You might need a loop stopper code, I use a loop stopper all the time.

You can also narrow down by using RewriteCond %{REQUEST_URI} !^this [NC] before your rewriterule, that way at least the rewriterule won't hit everything
posted by mrapache at 5:20 AM on March 31, 2007


« Older Whence the beatings?   |   Hypothyroid or hypochondriac? Newer »
This thread is closed to new comments.