我仍然可以将 PHP GET 变量与 mod_rewrite 一起使用吗

发布于 2024-12-28 12:13:15 字数 461 浏览 3 评论 0原文

我有一个页面,它使用以下代码从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尐籹人 2025-01-04 12:13:15

如果您的 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.

情独悲 2025-01-04 12:13:15

是的,当您使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文