0

.htacessファイルと URL のエイリアシングとGET値を取得する方法に問題があります

.htaccess ファイル

<IfModule mod_rewrite.c>
    # Enable Rewriting 
    RewriteEngine on 
    RewriteRule ^search-location/(\w+)/?$ findjob4.php?loc=$1
</IfModule>

findjob.php ファイル

if (isset($_GET['loc']) or !empty($_GET['loc'])) {
    $d_location = $_GET['loc'];
    echo "Location : " . $d_location;
}

以下は私がした操作です、

URL 1   :   www.example.com/search-location/london
ouput   :   Location : london
status  :   Good


URL 2   :   www.example.com/search-location/north-london
output  :   Error 404 , Object not found!
Status  :   The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.


URL 3   :   www.example.com/search-location/north%20london
output  :   Error 404 , Object not found!
Status  :   The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

しかし、URL 値の間に (スペース) または(ハイフン) を指定すると、これらのGETメソッドloc変数の値を取得できませんでした。URLから値を取得するにはどうすればよいですか... .-

ありがとう

4

1 に答える 1

1

which を単語だけでなく、何にでも一致するものに(\w+)置き換えてみてください。(.*)または、文字とダッシュ (-) だけが必要な場合は、これを使用できます:([A-Za-z-]+) また、.htaccess のデバッグに役立つこのツールもあります。

于 2012-05-25T11:50:04.337 に答える