Forum Moderators: phranque

Message Too Old, No Replies

How to deal with multiple redirects

htaccess redirects with no pattern matching

         

salewit

3:12 am on Apr 2, 2008 (gmt 0)

10+ Year Member



This is going to be hard to explain. Dynamic website started a few years ago with just 20 items with filenames like this:

www.domain.com/Widget.php
www.domain.com/Doohicky.php
www.domain.com/Whatchamacallit.php

Well since then, we now have over 700 items, and long ago created a single file to dynamically show the new items. But for the new items ONLY. The older static items weren't touched.

So if someone selects a Widget, they still go to widget.php. On the newer items, they go to "item.php?item=663"

Shortly after we did the dynamic stuff, we further decided that "item.php?item=663" wasn't too attractive to SE's and customers, so we did a rewriterule for the dynamic items... i.e.:

RewriteRule ^ITEM-.*_(.*)$ item.php?item=$1 [L]

And changed our items in the database to: ITEM-Purple-Widget_663

So if you still follow me... I've got about 500 items displayed dynamically usng a RewriteRule. Everything is great there. The remaining 250 items I *just* changed in the database to display dynamically. The problem is I have to redirect the old static items. I tried making a long Redirect list in .htaccess and it works up to about 38k in size. But anything larger than that and I get "Internal Server Error #500". I suspect there is a max limit on the size of htaccess.

Any suggestions? I hope I explained it properly.

jdMorgan

3:42 am on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've had up to 98kB with no trouble, so I'm not sure that's your problem. What's in your server error log when you get the 500-Server Error?

If all "static" page URLs were of the form xyz.php, where xyz was "Widget" and "Doohicky," etc., then why not redirect any request for any php URL except item.php to /ITEM-(something)_<pagename>, where (something) is a generic such as "product" and <pagename> is the original php page name (except for "item.php" as noted).

In other words, be sure to investigate *any* approach you might use to detect requests that need to be redirected. You can often use patterns, negative patterns, and file-exists checks to good effect.

Once you've 301-redirected a request for an old page to a new URL in the "ITEM-" taxonomy, your internal rewrite will happily send the newly-redirected request for it off to your item.php script.

If this approach won't work for your URL-set, then order your one-off redirects with bestsellers/highest-profit-item URLs first, and keep going until the file's too big -- If it ever does in fact get too big -- Your 500-Error could have been caused by a simple typo. Check that server error log before proceeding!

Jim

salewit

4:23 am on Apr 2, 2008 (gmt 0)

10+ Year Member



Thanks for the quick response. I feel kind of stupid right now. The error log pointed me to the problem right away. I had a stray space in one of the redirect filenames that wasn't supposed to be there. Everything's working fine now.

But I'll tell you, I don't like the idea of a 50k htaccess file, so I will try to explore some way to come up with patterns. We have a ton of other .php files on the site, so I don't see how I could just look for .php files.

Let me ask you this. What would your opinion be on how long one needs to have 301 redirects? Months? Years? Forever? It's basically just to inform the SE's of the new pages, AND any bookmarks or links to a specific page, correct? I guess I answered my own question. It seems like it's very site specific.

jdMorgan

8:55 pm on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



301s should stay forever, or until you know that there are no longer any links to the old URL left on the Web.

Best practice is to "design" URL plans, and keep them under control. The attitude should be: "We will never change another URL again, ever, and we will not remove any URLs in the future, ever." The Web should be viewed as a library and not as a weekly sales brochure.

In the practical world, that purist approach may prove impossible. But any deviation from that approach should be taken with regret, and not cavalierly.

You've already seen the pain that a lack of formal planning and control can cause, so I presume you'd rather avoid more in the future. ;)

A word from the inventor of the hyperlink [w3.org], Sir Tim Berners-Lee.

I sure hope you can come up with a pattern-based redirect approach! In the meantime, put the redirects in order from most-used to least used (based on your stats) for best performance.

Jim