使用 PHP + .htaccess 访问 GET 变量

编程入门 行业动态 更新时间:2024-10-23 21:32:57
本文介绍了使用 PHP + .htaccess 访问 GET 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 PHP 开发网站.我的 .htaccess 有这个重写规则:

I'm developing a website using PHP. My .htaccess has this rewrite rule:

RewriteEngine On RewriteRule ^book/([^/]*).html$ book.php?title=$1 [L]

所以 URL 看起来像:www.example/book.php?title=title-of-the-book变成 www.example/book/title-of-the-book.html

So the URL that looked like: www.example/book.php?title=title-of-the-book turns into www.example/book/title-of-the-book.html

在特定情况下,从站点的另一个页面,我想链接到这样的页面:www.example/book.php?title=title-of-the-book?myfield=1然后变成www.example/book/title-of-the-book.html?myfield=1.html

In a specific case, from another page in the site, I want to link to pages like this: www.example/book.php?title=title-of-the-book?myfield=1 that then turns into www.example/book/title-of-the-book.html?myfield=1.html

在那里,我无法使用通常的 PHP 方式访问 GET 变量

Being ther, I cannot acces the GET variables using the usual PHP way

$variable = $_GET['myfield']

我该如何解决这个问题?

How do I solve this problem?

推荐答案

Specify [QSA] (Query string append) 这样你就可以在你的 url 后面传递一个查询字符串.

Specify [QSA] (Query string append) so you may pass a query string after your url.

RewriteEngine On RewriteRule ^book/([^/]*).html$ book.php?title=$1 [QSA,L]

PS:你为什么在这里使用 * ?+ 不是更适合吗?

PS: Why are you using * here? Wouldn't + suit better?

更多推荐

使用 PHP + .htaccess 访问 GET 变量

本文发布于:2023-10-31 16:30:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546641.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   PHP   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!