views:

29

answers:

1

Hi,

Basically I have the following in my .htaccess file in the root of my site:

Options -Indexes

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
</IfModule>

In my PHP script when I use $_GET['route'] I get the following error:

Notice: Undefined index: route

I don't understand why this isn't working? I've used this code in the past on a previous website for friendly URLs and the PHP script got the GET request value fine, but it seems to be playing up now :/

When I do it manually like http://localhost/index.php?route=hmm the error goes away and I can get the value of $_GET['route']

What am I doing wrong? Ask if you need any additional information! Thanks for reading.

A: 

I use this for URI rewriting (routing):

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

And parse it with:

class Dispatcher {
    [snip]
    private static function parse_uri() {
        if (self::$uri_parsed === false) {
            // Clean URI
            $uri = preg_replace('~|/+$|/(?=/)~', '', $_SERVER['REQUEST_URI']);

            // Strip get variables from request
            $get_position = strpos($uri, '?');
            if ($get_position !== false) {
                $striped_get = substr($uri, 0, $get_position);
            } else {
                $striped_get = $uri;
            }

            // Get the file and directory of the request
            if (strstr($striped_get, '.') != false) {
                // Strip the file from the URI
                $slash_position = strrpos($striped_get, '/');
                if ($slash_position !== false) {
                    $striped_file = substr($striped_get, 0, $slash_position + 1);
                } else {
                    $striped_file = $striped_get;
                }
                self::$command = $striped_file;
                self::$file    = substr($striped_get, strlen(self::$command));
            } else {
                self::$command = $striped_get;
                self::$file    = '';
            }
            // Trim slashes and replace dashes with underscores
            self::$command = str_replace('-', '_', trim(self::$command, '/'));

            if (DEBUG) {
                // Log the results
                Logger::log('Command: '.self::$command, self::LOG_TYPE);
                Logger::log('File: '.(self::$file ? self::$file : 'N/A'), self::LOG_TYPE);
            }

            self::$uri_parsed = true;
        }
    }
    [snip]
}
Petah