开发者

Clean AND "dirty" url

开发者 https://www.devze.com 2023-02-10 02:25 出处:网络
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\'.

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} 开发者_如何学Go!-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/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号