重写给我不需要的$ _get参数

发布于 2025-02-13 21:36:42 字数 516 浏览 0 评论 0原文

我需要video/5 be video.php?id = 5

RewriteRule ^video$ video.php [L]
RewriteRule ^video/([^/]*)/?$ video.php?id=$1 [QSA,NC,L]

高度 - 上述代码工作 - 但这是一个问题:

video/ - 没有ID - 给我一个空字符串,为$ _ get ['id']

因此,如果我编写:

if(ISSET($ _ get ['id ['id']) ))... - 结果是true,值是“”

如何避免这种情况?

我只需要视频/ - 没有任何$ _GET变量 - 除非明确设置 - 例如 - video/5

I need video/5 to be video.php?id=5

RewriteRule ^video$ video.php [L]
RewriteRule ^video/([^/]*)/?$ video.php?id=$1 [QSA,NC,L]

esentially - the above code works - but here is a problem:

video/ - without id - gives me an empty string as $_GET['id']

so if I write:

if(isset($_GET['id']))... - the result is true and the value is ""

how to avoid this ?

I want just video/ - without any $_GET variable - except it is set explicitly - for example - video/5

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

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

发布评论

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

评论(1

风吹过旳痕迹 2025-02-20 21:36:42

使用您显示的样本,请尝试遵循HTACCESS规则。在测试URL之前,请确保清除浏览器缓存。

RewriteEngine ON
##Internal rewrite to video.php without $1 in it.
RewriteRule ^video/?$ video.php [NC,L]

##Rules for internal rewrite with passing id query string to it.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^video/([^/]*)/?$ video.php?id=$1 [QSA,NC,L]

With your shown samples, please try following htaccess rules. Make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##Internal rewrite to video.php without $1 in it.
RewriteRule ^video/?$ video.php [NC,L]

##Rules for internal rewrite with passing id query string to it.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^video/([^/]*)/?$ video.php?id=$1 [QSA,NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文