2

I made a htaccess for clean urls that is processed by PHP after, however for my search option I want a youtube-like '?q=searchquery'.

RewriteEngine on RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^(.*)/$ index.php?d=$1 [L] 

That's my htaccess and it works for all urls but 'http://www.website.com/search/?q=searchquery' doesn't. Now I've tried other rewrites such as these

RewriteRule ^(.*)/\?(.*)/$ index.php?d=$1&$2 RewriteRule ^(.*)/\?q=(.*)/$ index.php?d=$1&q=$2 

They dont work.

I also had a look the entire URI using the [R] flag and everything from the question mark doesn't show.

RewriteRule ^(.*)/$ index.php?d=$1 [L] 

Using the url: http://www.website.com/search/?q=searchquery displays: http://www.website.com/search/

Edit: So how do I do both? \o/

3

1 Answer 1

5

Just use the QSA (Query String Append) flag:

RewriteRule ^(.*)/$ index.php?d=$1 [L,QSA] 

If the URL is called with a query string, the query string is appended to the generated URL.

PS: You can't match a query string within the rewrite rule. The query string is stripped off, before the rules are matched.

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

4 Comments

@Tim: If that's the answer you were looking for, click on the transparent green tick next to it ;)
I've tried that about a million times, but it tells me I have to wait. I'll definately keep clicking until it works! Thanks man
@Tim: Probably there is some timespan which you can't accept the answer in.
Yeh I did it, made an account and gave you thumb up, even though its an arrow \o/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.