Forum Moderators: phranque

Message Too Old, No Replies

Dynamic Mod-Rewrite for 1mill pages.

bar/i-like-corn-pies --> foo?id=5

         

Vali

3:20 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



Hi

Not sure if this has been asked before, but I couldn’t find any info on it.

I want to make my pages more SEO friendly, so I want to turn:
www.my-site.com/foo?c=1&id=234
to
www.my-site.com/cooking/I-like-corn-pies

That's no problem. But how could I do this for lets say 1mill pages. (Not that I have that many, but you get the idea.)
Writing one line per db entry seams like a bad idea, and it would create a huge file, so there must be some other way.

Could you guys enlighten me a bit?

Vali

jdMorgan

4:33 pm on Sep 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the most difficult application for URL rewriting. If the old and new URLs are not directly related, requiring only a simple "rearrangement" of the text information in the existing URL to get the new URL, then a database lookup is required.

Two solutions are:

1) Add the new friendly URLs to the existing database itself, and modify your script to use the new URLs on your pages and to do the redirects when needed.

-or-

2) Use mod_rewrite's RewriteMap to call a script to do a lookup in that database, or in a separate one, to redirect the old c=x&id=y URLs to the new descriptive URLs. (You must still modify your script to use the new URLs on the pages it generates, though.)

Jim

Vali

6:02 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



"RewriteMap", cool I found what I was looking for.

I basically point everything to a script that will look up the stuff in the database, and then return the appropriate page.

Thank you

thaedge

3:25 pm on Sep 19, 2006 (gmt 0)

10+ Year Member



Vali as Im no expert with anything Mod Rewrites, but based on how jdMorgan described a RewriteMap I could also say to simply use code.

In my past life prior to my current job of using Apache/PHP I worked with ColdFusion. In ColdFusion and I assume most other web languages its possible to do something like a RewriteMap at the code level.

Ive done this for a few sites (page numbers in the 50k+ range) and were able to move this from one server to another easily, across multi servers, and had great control over the wide variety of page types(templates). Im not saying this is the best solution for you - but a possible option.

jdMorgan

7:37 pm on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is the purpose of RewriteMap as recommended in this application. RewriteMap can be used to invoke a script which accesses the same database used to perform the previous reverse-transform. In this way, all URL redirect and rewrite maintenance can be done in the database, using whatever GUI has been previously developed for all the other site maintenance.

It is most useful when an internal rewrite is desired based on a client-requested URL which cannot be directly mapped to a server filepath or script invokation by a simple text-transform or rearrangement of the URL, as is the case if the requested URL is /small-green-widget and the actual path is /products.php?prodid=102347

In a case like this, the database is organized based on product ID numbers, and the script looks up the URL to be published as a link on the page for bookmark, usability, and SEO purposes. When that URL is subsequently requested from the server by a client, RewriteMap can call a script to look up the correct product id needed to call the script, using the inverse of the process used for on-page link publishing.

And as mentioned previously, if the script can be customized, then this lookup function can indeed be done within the script itself, as long as the requested URLs which should invoke the script are sufficiently unique for a simple mod_rewrite pattern to identify and forward the request to the script.

Jim