php:摆脱 ?p= url 中的查询? [英] php: getting rid of ?p= query in url?
问题描述
嘿伙计们,我不是在寻找 mod_rewrite 的东西或任何相关的东西.我只是不确定这是否可能?
hey guys, i'm not looking for a mod_rewrite thing or anything related. i'm just not sure if this is possible or not?
我正在使用 if(isset($_GET['p'])) ... 来检查 ?p=something 是否在我的 url 中设置,如果没有 $foo = "bar";如果设置了 ?p=,例如?p=something –> $foo = "something".有我吗?
i'm using if(isset($_GET['p'])) … to check if ?p=something is set in my url, if not $foo = "bar"; if a ?p= is set e.g. ?p=something –> $foo = "something". got me?
如果我现在手动输入 ?p=bar 到我的 url 中,我的 url 中的字符串实际上是默认字符串.因为如果我的 url 中没有 ?p $foo = "bar";
if i manually enter now ?p=bar to my url the string in my url is actually the default one. Because if I don't have a ?p in my url $foo = "bar";
我想知道是否是这种情况我可以完全摆脱我的网址中的 ?p= 部分?如果默认字符串设置为我的 $foo 变量,我只想有一个干净的 url,我的 url 中没有任何干扰?p=bar.
I wonder if that's the case i can get totally get rid of the ?p= part in my url? if the default string is set to my $foo variable i just wanna have a clean url without any distractign ?p=bar in my url.
对不起,奇怪的 foo 和 bar 的东西,我没有更好的例子;)问候马特
sorry for the weird foo and bar stuff, i had no better example ;) regards matt
推荐答案
if ($_GET['p'] == 'bar') {
parse_str($_SERVER['QUERY_STRING'], $q);
unset($q['p']);
header('Location: ' . $_SERVER['PHP_SELF'] . ($q ? "?" . http_build_query($q) : ''));
}
是一种巧妙的方式.它不会清除其他 GET 参数(如果存在).
is a neat way. It does not wipe other GET parameters, if they exist.
这篇关于php:摆脱 ?p= url 中的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!