访问GET变量PHP +的.htaccess变量、GET、htaccess、PHP

2023-09-02 00:28:00 作者:我的世界我主宰

我用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]

所以,看起来像的网址:www.example.com/book.php?title=title-of-the-book 变成www.example.com/book/title-of-the-book.html

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

在一个特定的情况下,从网站的另一个页面,我要链接到这样的页面: www.example.com/book.php?title=title-of-the-book?myfield=1 这则变成 www.example.com/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.com/book.php?title=title-of-the-book?myfield=1 that then turns into www.example.com/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?

推荐答案

指定 [QSA] (查询字符串追加),这样你的网址后,你可以通过查询字符串。

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?