.htaccess 查询字符串小问题?

发布于 2024-09-19 01:47:10 字数 460 浏览 2 评论 0原文

我的 php:

if(isset($_GET['text'])) {
 $text = $_GET['text'];
} else {
 $text = "default"; //if no ?text= set then print "default"
}

我的 .htaccess

RewriteEngine On
RewriteRule ^(.*)$ index.php?text=$1 [L,QSA]

.htaccess 实际上工作得很好,除非我没有将文本设置为我的网址,否则我的 else 语句(“默认”)不起作用。

所以如果输入 mydomain.com/whatthe 一切正常 ($text = "whatthe";) 然而,当我只是调用 mydomain.com $text 是空的而不是包含“默认”。

我做错了什么?

my php:

if(isset($_GET['text'])) {
 $text = $_GET['text'];
} else {
 $text = "default"; //if no ?text= set then print "default"
}

my .htaccess

RewriteEngine On
RewriteRule ^(.*)$ index.php?text=$1 [L,QSA]

the .htaccess works actually fine, except if i don't set text to my url my else statement ("default") doesn't work.

so if enter mydomain.com/whatthe everything works fine ($text = "whatthe";)
however when i just call mydomain.com $text is empty instead of cotaining "default".

what do i wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

ゃ人海孤独症 2024-09-26 01:47:10

发生的情况是您仍在设置 GET 变量,尽管设置为 null 或空字符串。

你应该使用:

if(isset($_GET['text'] && !empty($_GET['text'])) {

What is happening is that you are still setting the GET variable, albeit to null or an empty string.

You should use:

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