Hello,

I have searched around for Mod Rewrite alternatives for non-Apache webservers but I can't find any, although I found a patch-dependent solution for IIS - which was still inapplicable to us non-IIS and non-Apache needs. I use Abyss webserver and Drupal 4.6.5, and I found this neat little code from Aprelium's website but I'm not yet PHP-coding savvy to make it work. Hopefully somebody out there can apply edits on this code so that us non-Apache users can also enjoy clean URLs too.

The main idea is to put PHP code in the default 404 resource so that a silent redirection is made to the correct resource. This idea is summarized in the code logic as follows:
Let's say a surfer wants to browse http://site/foo/bar. Since the surfer really wants http://site/index.php?q=foo/bar and that the resource http://site/foo/bar is really non-existent, the following PHP'd 404 code will be executed:

    if http://site/index.php?q=foo/bar exists then
        redirect requested http://site/foo/bar to http://site/index.php?q=foo/bar using http status code 302 or an unconventional 307 to make it silent(?)
    elseif http://site/index.php?q=foo/bar does not exist then
        serve the actual 404 - resource not found
    endif

The code below has been taken from Aprelium's website: http://www.aprelium.com/forum/viewtopic.php?t=7865

< ? php

/* Add in this array the list of (old path = > new path) pairs */
$ redirection = array(
   '^wiki/?(.*)$' = > '/w/index.php?title=$1'
);

/* Get the URI and trim leading slashes */
$uri = ltrim($_SERVER["REDIRECT_SCRIPT_NAME"], "/");

foreach ($redirection as $key => $value)
{
   if (eregi($key, $uri))
   {
        /* Convert the replacement string syntax - $1 -> \1 */
        /* and perform the substitution */
      $new_uri = eregi_replace($key, str_replace("$", "\\", $value), $uri);
      break;
   }
}

if (isset($new_uri))
{
   header("Status: 307");
   header("Location: $new_uri");
   exit;
}

?>

< ! -- Your 404 error page -- >

< HTML >
< HEAD >
< TITLE >
Not Found
< /TITLE >
< /HEAD >
< BODY >
The object < tt >< ? php echo $uri; ? >< /tt > is not available.
< /BODY >
< /HTML >

Note: Angled brackets and php tags had to be spaced out to make the Drupal website accept this submission.

I guess I need help in the replacement section. Thank you very much for your ideas and helpful insights.

Comments

loloyd’s picture

Bumping thread. *sigh*

sepeck’s picture

The vast majority of folks use Apache. I figure you've seen this bit for IIS http://drupal.org/node/3854 and if not there it is. Steven included a note and I am trying to puzzle through the note in my spare time myself but having to figure out php while doing so is well, slow. :)

Perhaps it will help point you in a direction.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide