gpt4 book ai didi

php - htaccess 检查查询字符串是否为空

转载 作者:行者123 更新时间:2023-12-02 13:01:30 26 4
gpt4 key购买 nike

我的服务器有以下情况:

/->
news->
.htaccess
index.php
post.php
...

以及我的 .htaccess 中的以下规则:

RewriteRule    ^(.*)/admin          post.php?slug=$1&admin_mode=true            [NC,QSA,L]
RewriteRule ^(.*)$ post.php?slug=$1 [NC,QSA,L]

现在我需要的 URL 如下:

If requested www.mydomain.com/news/ -> it should get the index.php file

If requested www.mydomain.com/friendly-title-of-my-article -> it should get the post.php file with the query string as indicated in my .htaccess.

目前,我使用查询字符串正确获取了 post.php,但是当我访问 www.mydomain.com/news/时,它正在请求 post.php 文件。

请帮忙。谢谢

最佳答案

使用这个

#if query string is empty

RewriteCond %{QUERY_STRING} ^$

#match on / for root, or .index.php in request and send to query string version

RewriteRule ^(/|index.php)?$ /index.php?step=1 [R=301,L]

关于php - htaccess 检查查询字符串是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33892352/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com