How to get query string and rewrite it in htaccess

2019-03-02 17:15发布

问题:

I have queries like this:

example.com/folder/?q=keyword

Please suggest how to redirect all queries that contain "keyword" as a parameter to other file on server:

/folder/core/index.php?id=$1

I mean $1 must be keyword

Here is my example:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=\/(.*)$
RewriteRule ^/?$  /folder/core/index.php?id=$1 [L]

回答1:

If you are using .htaccess in folder/ directory then try with below,

RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=(.+)$
RewriteRule ^ /folder/core/index.php?id=%1 [QSA,L]