Tim S.
Tim S.

Reputation: 13843

Clean AND "dirty" url

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/

Upvotes: 2

Views: 805

Answers (1)

NikiC
NikiC

Reputation: 101936

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.

Upvotes: 5

Related Questions