php Rewrite Map needed

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
alhermette
Forum Newbie
Posts: 7
Joined: Fri Jun 05, 2009 4:36 am

php Rewrite Map needed

Post by alhermette »

I need to create a rewrite map in php and this is totally uncharted territory for me and lengthy searches online have not provided the info that I need so far. I hope that this is the right topic to post under.

If you need to understand my reasons for needing a rewrite map you can follow my thread on the mod_rewrite forum here: http://forum.modrewrite.com/viewtopic.p ... 61&start=0

I understand that when my php scipt is called by httpd.conf the requested url will be passed to the script in STDIN and that my modified url must be output on STDOUT. I can write standard php code to perform the manipulations required to the url no problem. Apparently for a rewrite map the php must run from the command line and I have no idea if this affects the way the code should be written or limits in any way the functions that I can use. I certainly need to use sessions and ideally would like to use a cross domain include if that is possible.

What I need help with is creating the rewrite map page. How do I start the file and assign STDIN to a variable that I can manipulate and how do I finish the file so that the modified url is passed to STDOUT? This is what I have come up with so far but I really have no idea if it is correct or not.

Code: Select all

#!/usr/bin/php
<?php
 
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout','w');
 
while( $url = trim(fgets($stdin)))
{
// Put my php processing script here that modifies $url
fwrite($stdout, $url.".html\r\n");
}
?>
If anyone is able to assist I would be most grateful.
Last edited by Benjamin on Fri Jun 05, 2009 11:25 am, edited 1 time in total.
Reason: Changed code type from text to php.
alhermette
Forum Newbie
Posts: 7
Joined: Fri Jun 05, 2009 4:36 am

Re: php Rewrite Map needed

Post by alhermette »

Anyone got any suggestions as to where I may be able to get help with this?
Post Reply