Jump to content

Apache Php Rewrite


Monotoba

Recommended Posts

Can anyone here help me with a small problem I'm having?

 

I am trying to use PHP4/5 to implement a mod_rewrite script using apache2 mod_rewrite's "prg" map type. The reason for this is that I need to dynamically redirect urls using a database of mapping values. A seperate script will be used to edit the db records.

 

My development environment is WAMP on Vista. I am calling my php script from a bat file. The issue I am having is that I can't seem to get php to read or write on the stdin and stdout. My test php code to accomplish this is as follows:

 

 

<?php

/**

* Test script to echo url back to mod_rewrite

*/

 

$stdin = fopen('php://stdin', 'r');

 

$request = fread($stdin, 1024);

 

$stdout = fopen('php://stdout', 'w');

 

$map_path = $request;

 

fwrite($stdout, $map_path, 1024);

 

?>

 

My MySQL Table looks like this:

 

CREATE TABLE `routes` (

  `id` int(11) NOT NULL auto_increment,

  `request_url` varchar(255) NOT NULL,

  `local_path` varchar(255) NOT NULL,

  `ordinal` tinyint(8) NOT NULL,

  `status` varchar(20) NOT NULL,

  PRIMARY KEY  (`id`),

  KEY `request_url` (`request_url`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT=\'This table holds server site url mappings\' AUTO_INCREMENT=0 ;

 

 

 

And my Apache Config lcontains this:

 

 

 

#

# Mod Rewrite

#

<IfModule rewrite_module>

  #

  # Use

  #

  RewriteEngine on

 

  RewriteMap db_route_map prg:"C:/wamp/apache2/db_route/db_route.bat"

 

  RewriteRule ^/(.*)$  /${db_route_map:$1}

 

</IfModule>

 

The completed script will return the mapped paths contained in the db.

 

I suspect that I am not access the the stdin and stdout correctly.

 

Any ideas?

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.