Re: Installing under IIS6.0
| From: | Tjoekbezoer van Damme | Date: | Mon, 19 Sep 2005 21:47:44 +0000 |
| Subject: | Re: Installing under IIS6.0 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-222699@lists.php.net to get a copy of this message | ||
> I've got PHP set up to the point where it will process files ending in
> .php, but I want to "blanket" the processing of PHP code under IIS in
> the same manner in which I blanket PHP code with Apache.
>
> If anyone has any suggestions, other than reading PHP's manual which
> I've read several times which does not cover this, I would greatly
> appreciate it.
I wrote a little 'hack' to mimic modrewrite for IIS. When you get a
404 error page in IIS, you get the URL of the originally requested
page in the $_SERVER['QUERY_STRING'] variable. So by creating a custom
404 error page with this knowledge you can mimic the basic
functionality of modrewrite:
<?php
/*
Simple PHP script that imitates mod_rewrite for IIS 6.0
Set this script to be your 404 error document in the folder where you
want mod_rewrite to be enabled
Your rule can contain regular expressions in the Perl 5 syntax (PCRE).
You can use references in your target ($1, $2, etc) to refer back to
parts of your rule.
*/
$rule = "/(.*?)\/content\/([a-zA-Z0-9]+)\/([0-9]+)/m"; // Original URL
that is typed in the browser
$target = "/oilpowered.com/index.php?type=$2&id=$3"; // Redirect to
the new URL. Only relative URLs!
$qs = $_SERVER['QUERY_STRING'];
$url = substr( $qs, strpos( $qs, ";" )+1 );
// TODO: $page - preg_replace() in the if clause, to save one regexp?
if( preg_match( $rule, $url ) > 0 )
{
$page = preg_replace( $rule, $target, $url );
header( "Referer: " . $_SERVER['HTTP_REFERER'] );
header( "Location: " . $page );
}
?>
Hope this helps,
Tjoek