我仍然可以将 PHP GET 变量与 mod_rewrite 一起使用吗
我有一个页面,它使用以下代码从 URL 获取 GET
变量 q:
<?php ob_start(); session_start();
$q=trim($_GET['q']); // this is for security purposes
if (!is_numeric($q)){
header("HTTP/1.0 404 Not Found");
}
?>
当前 URL 看起来像 localhost/s/index.php?q=345
。我很快就会编写一个 .htaccess 文件,使 URL 看起来像 localhost/345。我想知道我是否仍然可以使用上面的代码获取 GET
变量 (q)。我担心它不会工作,因为 URL 不会具有典型的 GET
外观。在新 URL 中,“GET”变量将看起来像一个文件夹。
I have a page that takes a GET
variable, q from the URL using the following code:
<?php ob_start(); session_start();
$q=trim($_GET['q']); // this is for security purposes
if (!is_numeric($q)){
header("HTTP/1.0 404 Not Found");
}
?>
The current URL looks like localhost/s/index.php?q=345
. I will soon write a .htaccess file that makes the URL look like localhost/345. I was wondering if i could still grab the GET
variable (q) using the code above. I'm concerened it wont work because the URL won't have the typical GET
appearance. In the new URL the "GET" variable will look like a folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的
RewriteRule
替换字符串不包含?
简介,则查询字符串将保持不变。如果确实如此,并且您还指定了[qsa]
标志,则现有查询字符串将附加到替换字符串中的新查询字符串中。If your
RewriteRule
substitution string doesn't contain a?
intro then the query string is left unchanged. If it does and you also specify a[qsa]
flag then the existing query string will be appended to the new one in your substitution string.是的,当您使用 mod-rewrite 时,它会被“重写”成不同的格式。然后,您的 htaccess 将指定如何解释新格式,因此您的值将在那里,由您决定 htaccess 的格式以使它们获取变量。
Yes, when you use mod-rewrite, it is 'rewritten' into a different format. Your htaccess will then specify how to interpret the new format, so your values will be there, its up to you on the formatting of your htaccess to make them get variables.