簡體   English   中英

PHP Apache mod_rewrite

[英]PHP Apache mod_rewrite

這是基本信息:我在Windows 8 64位上使用WAMP。 Apache 2.4.2,PHP 5.4+。

我的項目文件位於http://localhost/test/ 該文件夾中的.htaccess文件是:

RewriteEngine on

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?$1 [L,QSA]

如果我輸入http://localhost/test/some/cool/stuff/類的URL,則可以正常工作

即在PHP中: $_SERVER['QUERY_STRING'] = index.php&some/cool/stuff/
我希望它也去除了index.php& ,但是我正在PHP中這樣做。

雖然如果我輸入類似http://localhost/test/some/cool/stuff的URL,PHP $_SERVER['QUERY_STRING']將返回index.php&some/cool/stuff/&some/cool/stuff

這個&some/cool/stuff/零件來自哪里?

我使用RewriteRule ^(.+)$ index.php [L] ,然后通過$_SERVER['REQUEST_URI']獲取URL

我對PHP使用此函數來獲取帶有備用的請求URL。

private static function get_request_URL() {
    if (isset($_SERVER["REDIRECT_URL"])) {
        $realURL = $_SERVER["REDIRECT_URL"];
    } elseif (isset($_SERVER["REQUEST_URI"])) {
        list($realURL) = explode("?", $_SERVER["REQUEST_URI"]);
    } else {
        return null;
    }
    $realURL = rtrim(trim(strtolower($realURL)), "/");
    if ($realURL == "") {
        $realURL = "/";
    }
    return $realURL;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM