Forum Moderators: phranque

Message Too Old, No Replies

database driven rewriting?

         

gergoe

9:21 pm on May 6, 2004 (gmt 0)

10+ Year Member


i have a quite big site with loads of files and directories, and i need to implement the following: www.example.com/**** (where the xxx is a two to ten letter code, threat as .{2,10}, but no extension) should be served by a server side script, but only if the xxx is a valid item in a database.

so if i have abc and def in the database, then the www.example.com/abc should be served by the script mentioned above (can be a redirection also), but the www.example.com/xyz should be handled by the apache (if it is a valid file/dir then process it; if it does not exists then send the browser away with a 404)

the website is used quite heavily (80k hits a day), so i need something which is quick enough and not resource intense (not like an external rewriting script, which is slow imho)

thanks

jdMorgan

12:07 am on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use RewriteMap, but that's only available at the server config (httpd.conf) level.

I think you'll hace to use the script to validate the requests.

Jim

gergoe

7:41 am on May 7, 2004 (gmt 0)

10+ Year Member


i can change the serverconfig, that's not a problem; but if i use RewriteMap, how i can force the apache to access the database? or you was thinking of puting the content of the database into a txt file some way?

jdMorgan

2:24 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, One way or another, the script has to be involved because there is no Apache function sophisticated enough to do this on its own.

So, either the script can validate requests - checking for existence of a db record - on the fly, or it can create a RewriteMap dynamically, maybe once an hour, and overwrite the previous one. This latter approach might offer an overall speed advantage, but the RewriteMap won't be up-to-date more than once an hour. If it needs to be synchronized to the minute or second, then there is no advatage and you might as well use a script to do the db-record-exists checking. This could be your main script, or perhaps a separate one optimized for doing the check.

Jim

gergoe

9:48 am on May 8, 2004 (gmt 0)

10+ Year Member



the database is not changing frequently, few times a year only, but it has about 100-200 distinct record in it, does it not cause a performace hit on modrewrite? if i put a rewritecond before the rules, to see that the request can be a valid request at all, then check the database only after this, then it should be fast, no?

jdMorgan

1:10 am on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This depends on your server CPU speed, amount of memory, cache size, disk access time, and the amount of traffic to your site. The only way to evaluate the impact of such a rewrite on a given server is to try it.

Jim

paybacksa

1:20 am on May 9, 2004 (gmt 0)

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



Perhaps I am missing something, but can't you just generate /abc/index.html, def/index.html and NOT generate xyz/index.html, so that a call to xyz/index.html throws an 404 which you handle with a custom404erorhandler script?

Your directory tree becomes your database, and Apache does indeed consult it before throwing an exception (or serving the page).

Of course all those generated statics are really just shells to your includes...