How to get query string and rewrite it in htaccess

2019-03-02 17:10发布

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条回答
ら.Afraid
2楼-- · 2019-03-02 17:22

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]
查看更多
登录 后发表回答