2010-10-17 21 views
0

基本上我已經在我的.htaccess文件在我的網站的根目錄下:PHP/Apache:GET請求不存在?

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> 

在當我用我的PHP腳本$ _GET [「路線」]我得到以下錯誤:

Notice: Undefined index: route 

我不明白爲什麼這不起作用? 我用這個代碼在過去以前的網站友好的URL和PHP腳本上得到了GET請求值很好,但它現在似乎被打了起來:/

當我做手工像http://localhost/index.php?route=hmm的錯誤消失,我可以得到$ _GET ['route']的值

我在做什麼錯了? 詢問您是否需要任何其他信息! 感謝您的閱讀。

+0

嘗試一些調試。 print_r($ _ GET)說什麼? print_r($ _ SERVER)說什麼? – TuomasR 2010-10-17 17:48:03

+0

你能舉個例子嗎?你在使用框架嗎? – 2010-10-17 17:48:07

+0

TuomasR:print_r($ _GET)outputs Array() – AlexPriceAP 2010-10-17 17:53:38

回答

0

我用這個URI重寫(路由):

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

並與解析它:

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] 
}