1

I have an htaccess file that currently directs the entire url minus any query string to a query string variable url....

RewriteRule ^([a-z0-9_-/]+)/?$ index.php?url=$1 [NC,L]

page/subpage/important/thingy/?t=10

becomes

index.php?url=page/subpage/important/thingy/

the query string was ignored by design originally. now we need it added but in such a way that...

page/subpage/important/thingy/?t=10&name=Bob&food=cheese

should become...

index.php?url=page/subpage/important/thingy/&t=10&name=Bob&food=cheese

in short, the user-friendly component is assigned to a get variable url and the rest are tacked on.

Can anyone tell me where to begin with this or how to modify the rewrite rule to allow this?

2 Answers 2

1

You only have to use QSA flag to append query string.

RewriteRule ^([a-z0-9_-/]+)/?$ index.php?url=$1 [NC,L,QSA]
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Justin. I modified the htaccess file accordingly, I entered /home/?hello=dolly&me=hungry and the part sent to the $_GET['url'] was /home/. Is there a conflict in the reg ex?
This is a normal behaviour since you get other params with $_GET['food'] and $_GET['name'] following your question's example. If you want it to be part of url param, you must encode &
Yes, you're right. I thought it would be added to the end of the string passed to $_GET['url']. Sorry, yesterday was a long day! Thanks.
0

According to http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa @Justin Iurman's answer should have solved it, i.e. the QSA flag.

I finally managed to get this working using the following:

RewriteRule ^([a-z0-9_-/]+)?$ index.php?url=$1&%{QUERY_STRING} [NC,L]

Comments

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.