Php created list in .htaccess

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Php created list in .htaccess

Post by Todd_Z »

I am going to have about 200 pages which I would like to have in the form

http://www.domain.com/Page Name/

which would be mod_rewritten into

http://www.domain.com/landingPage.php?k=Page Name

I only want to redirect the pages that are present in a mysql database. Is it possible to mod_rewrite based on a list outputt by a php file [the php file would read all entries in a table and echo them].
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Since .htaccess is read before any content is served you won't be able to do it in realtime. The only thing I can think of is to have CRON run every 30 mins or whatever and modify your .htaccess file based upon the database contents...

It's not perfect though.

EDIT | Depending upon how your database is managed you may even be able to have a PHP script update the .htaccess file in synchronisation with updates to the database :idea:
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

What the, I though I answered this one...
Well well, eitherway, why can't you just mod_rewrite to a static php-file? (the sent address can be found in $_SERVER)

That way the script can do some nice db-query, view the page, do a redirect (if you want it that way), or thrown an error if it is desired.

Works really well.
Post Reply