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 值之间给出(空格)或(hypen),我无法获得这些GET方法loc变量的值。我如何从网址中获取值... .-

谢谢

4

1 回答 1

1

尝试用 which 替换(\w+)匹配(.*)任何内容而不仅仅是一个单词。或者,如果您只需要字符和破折号 (-),您可以使用以下命令:([A-Za-z-]+) 此外,还有一个工具可以帮助调试 .htaccess 内容。

于 2012-05-25T11:50:04.337 回答