Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Using a MySQL database to control mod_rewrite via PHP
Question: How can I set up Apache httpd / mod_proxy to use a program rather that a list of URL patterns to control my rewrites?

Specify a rewrite map type prg in your httpd.conf or .htaccess file. For example:

RewriteEngine On
RewriteMap tryme prg:/home/trainee/website/andy
RewriteRule (.*\.htm) ${tryme:$1}


Question: How can I write that program in PHP

1. Start the script with a line such as
#!/usr/local/bin/php
or a pointer to whereever the cli version of PHP is located.

2. Ensure you have a
set_time_limit(0);
at the top of that code to ensure it won't time out

3. Open your STDIN for interactive read within the PHP:
$keyboard = fopen("php://stdin","r");

4. Write a daemonic loop to read from keyboard, translate as appropriate, and printg out the mapped URL.

When you restart you httpd with the newly configured httpd.conf, your mapping should be in place. Well - it works for me ;-) but you do need to watch things like buffering!

Question: Can that program access a MySQL database?

Yes - just add in a mysql_connect or mysqli_connect at the top of your code, and appropriate database queries further down, and that's all there is too it. Remember you may need to "bounce" your web server to restart the rewrite daemon.

Putting all the answers together?

There's source code showing most of this ... a fully working example .. here
(written 2007-10-06 00:08:23)

 
Associated topics are indexed under
A603 - Web Application Deployment - Further httpd Configuration
H115 - Designing PHP-Based Solutions: Best Practice
S156 - Interfacing Applications to MySQL Databases

Back to
Static variables in PHP
Previous and next
or
Horse's mouth home
Forward to
First Great Western - information for customers

Some other Articles
Delegates of all shapes and sizes
An email update for past guests and delegates
Monitoring mod_jk and how it is load balancing
First Great Western - information for customers
Using a MySQL database to control mod_rewrite via PHP
Static variables in PHP
Simple page password protection - PHP
Etag in http headers - what is it?
Load Balancing with Apache mod_jk (httpd/Tomcat)
Choosing between mod_proxy and mod_rewrite
1638 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho