Forum Moderators: phranque

Message Too Old, No Replies

Best Way to Redirect 100 Pages?

         

Musicarl

5:17 am on Nov 18, 2009 (gmt 0)

10+ Year Member



We have a blog with about 100 entries that have URLs like:
http://www.example.com/folder/2009/11/post.html

We're switching to a different system and moving all these posts to new pages that will look like this:
http://www.example.com/blog/description/post_name/

What's the best way to redirect the 100 old pages to the new ones?

Here's my thought:

In http://www.example.com/folder/, put an .htaccess file in with 100 lines like this:

RewriteRule ^2009/11/post.html$ http://www.example.com/blog/description/post_name/ [NC,R=301,L]

I'd rather not redirect 100 pages like this, but can't think of a better way. Any ideas?

jdMorgan

1:30 pm on Nov 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The easiest alternative is to redirect them all to a script that can access your database to look up the new post-names for use in a client redirect. This assumes that your database contains the information necessary to do this.

I'm not being specific here about what script you use or which database you access because I don't know how flexible your blog script and database are, or whether you'd want to modify them. If not, then you can 'build your own' script and database or lookup table.

Also, if you have server config access permissions, look at mod_rewrite's RewriteMap directive and the syntax for 'calling' a rewritemap from a RewriteRule directive -- It's sometimes handy for this kind of problem.

Jim

Musicarl

2:03 pm on Nov 18, 2009 (gmt 0)

10+ Year Member



Thanks JD. Unfortunately, we don't have the existing blog in a database, which is one of the reasons we're moving away from it.

If we were to do this manually and create a .htaccess file with the 100 redirects in example.com/folder, would that be completely unwieldy? It would be a big file, but the only time it would get used is when people are trying to access our old links.

g1smd

3:12 pm on Nov 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can do this with the .htaccess file. I would do that if you do NOT want to add other entries later. This would be a "fix those 100 entries and forget it" solution.

Longer term I would rewrite those URL requests to a simple script you build yourself, and that script would look up the new URL in a database table that you build yourself. You can then have a simple way to maintain that table over time.

jdMorgan

3:14 pm on Nov 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



100 lines of code isn't really a big file.

And if you put the code into /folder/.htaccess, and only requests for 'old' pages will ever land in that subdirectory, then the effect on your site's performance will be utterly negligible.

Jim

g1smd

3:15 pm on Nov 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can do this with the .htaccess file. I would do that if you do NOT want to add other entries later. This would be a "fix those 100 entries and forget it" solution.

Longer term I would rewrite those URL requests to a simple script you build yourself, and that script would look up the new URL in a database table that you build yourself. You can then have a simple way to maintain that table over time.

Musicarl

4:25 pm on Nov 18, 2009 (gmt 0)

10+ Year Member



Yeah, this is a "fix it and forget it" situation, and we won't be adding any more pages to that folder. Writing the file will be a pain, but then we can pretty much leave it alone. Thanks for the help guys.