Access GET variables with PHP + .htaccess

我怕爱的太早我们不能终老 提交于 2019-11-27 07:13:15

问题


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

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

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

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

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

$variable = $_GET['myfield']

How do I solve this problem?


回答1:


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: Why are you using * here? Wouldn't + suit better?



来源:https://stackoverflow.com/questions/3375680/access-get-variables-with-php-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!