php - 使用 PHP + .htaccess 访问 GET 变量

标签 php .htaccess url-rewriting get

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

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

所以 URL 看起来像:www.example.com/book.php?title=title-of-the-book 变成 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

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

$variable = $_GET['myfield']

我该如何解决这个问题?

最佳答案

指定 [QSA](查询字符串附加),以便您可以在 url 之后传递查询字符串。

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

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

关于php - 使用 PHP + .htaccess 访问 GET 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3375680/

相关文章:

php - 使用所需格式的日期将 mySQL 导出到 Excel

来自搜索引擎的 PHP 数组总和

apache - 在 .htaccess 中设置 Content-Security-Policy header 时出现 500 Internal Server Error

wordpress htaccess如何删除除index.php之外的所有php扩展

java - 如何在 Tomcat 7 上使用 UrlRewriteFilter 缩短/清理 URL

IIS10 URL Rewrite 2.1 双编码问题

javascript - 在同一页面上创建钻取融合图表

php - 像stumbleupon这样的网站能打开google.com吗

.htaccess - URL重写Azure PHP?

正则表达式 : get the two letters after the slash or after the last dot