URL 中的空白空间不会使用 .htaccess 在 PHP 中生成任何页面


empty space in url makes no pages in php using .htaccess

我在使用文件和 url 别名以及GET检索值的方法时遇到问题.htacess

.htaccess 文件

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

查找作业.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 获取值。

谢谢

尝试将('w+)替换为与任何内容匹配的(.*),而不仅仅是一个单词。或者,如果您只想要字符和破折号 (-),您可以使用以下内容:([A-Za-z-]+)还有这个工具可以帮助调试.htaccess的东西。