使用.htacess
文件和网址别名以及GET
方法检索值时出现问题
<IfModule mod_rewrite.c>
# Enable Rewriting
RewriteEngine on
RewriteRule ^search-location/(\w+)/?$ findjob4.php?loc=$1
</IfModule>
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
(hypen),我无法获得这些. .
方法-
变量的值。
我如何从网址获取值..
感谢
答案 0 :(得分:1)
尝试将(\w+)
替换为匹配任何内容的(.*)
,而不仅仅是单词。或者,如果您只需要字符和短划线( - ),则可以使用:([A-Za-z-]+)
还有这个tool可以帮助调试.htaccess东西。