Mod_rewrite to eliminate query strings

Posted by Greg Frommer on Server Fault See other posts from Server Fault or by Greg Frommer
Published on 2010-04-21T20:55:32Z Indexed on 2010/04/21 21:03 UTC
Read the original article Hit count: 278

Hi everyone, I have been working on this for a while but I'm not finding exactly what I am looking for. I am writing a webapp to let my users create and publish pieces of HTML content in a domain and URL folder structure of their choosing. All of the content and requested URL structures are stored in a database. I have all of the code in my index.php (in the root folder) to access the database content, and based on the server name (and hopefully folder structure) will pick out the proper content from the DB and display it to the end-users browser. So my situation looks like this:

www.test.com/index.php?id=123234345 ... will display the proper page, but I want my users to be able to define a unique "page name" instead of using the numeric index (also I want to hide the /index.php part) so what I would like the end-user to see is:

www.test.com/arbitrary-unique-keyword/keyword2/keyword3

which will invoke the index.php page in the root folder. Then I will use the PHP $_SERVER['PATH_INFO'] variable to match the requested folder structure up with the proper content in my database and display that. All the material I have found so far expects me to hard code parts of the folder structure into the rules.... but I think I want something simpler (perhaps).

So the question in a nutshell: How do I use mod_rewrite to allow all "non-existent" folder paths be passed through to a main index.php residing in the root folder? (For all paths that DO exist, like for calls to images... I want those to succeed and not be directed to the index.php obviously)

Thanks everyone, please let me know if I can clear anything up.

© Server Fault or respective owner

Related posts about mod-rewrite

Related posts about folders