0

コード :

.htaccess:

RewriteEngine On  
RewriteRule    ^(.*)/*$    base.php?request=$1    [NC,L]  

base.php

<?php
    echo "this is base.php <br/> and Get Vaiables <br> ";
    print_r($_GET);
?>

リクエストの場合:

localhost/blahblahproject/hello  

期待される結果:

これは base.php
で、Vaiables
Array を取得します ( [request] => hello )

現在の結果:

これは base.php
で、Vaiables
Array を取得 ( [request] => base.php )

4

3 に答える 3

1

.htaccess ルールを次のように変更します。

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ /base.php?request=$1 [QSA,L] 
于 2013-02-13T10:21:32.513 に答える
0

.htaccessURL のみを get パラメータにリダイレクトします。URL 値を取得するには、parse_urlまたは同様のコマンドを使用します。

私は仕事をするためにこのような機能を持っています:

/**
 * Sets current request url
 */
private function setUrl() {
    $path = parse_url( $_SERVER[ 'REQUEST_URI' ], PHP_URL_PATH );
    $pathTrimmed = trim( $path, '/' );
    $pathTokens = explode( '/', $pathTrimmed );

    if ( substr( $path, -1 ) !== '/' ) {
        array_pop( $pathTokens );
    }

    $url = end( $pathTokens );

    $this -> url = $url;
}
于 2013-02-13T10:06:37.913 に答える
0

最後の "/" の後の文字列に関心がある場合は、.htaccess ファイルを次のように変更します。

RewriteEngine On
RewriteRule ^.*/(.*)$ base.php?request=$1    [NC,L]
于 2013-02-13T10:16:05.370 に答える