How to get query string and rewrite it in htaccess

时光毁灭记忆、已成空白 提交于 2019-12-02 09:30:04

问题


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]


来源:https://stackoverflow.com/questions/43818980/how-to-get-query-string-and-rewrite-it-in-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!