3

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 Answer 1

7

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?

Sign up to request clarification or add additional context in comments.

2 Comments

I don't know about the * and + . I don't understand very much about URL rewritin, so a friend of mine wrote these rules for me. Why do you think there should be a * instead of a + ?
* is zero or more characters, i.e. book/.html would be allowed, too. + is one or more characters, so book/.html wouldn't be matched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.