Home >Backend Development >PHP Tutorial >How does RewriteCond obtain multiple parameters in pseudo-static rules?

How does RewriteCond obtain multiple parameters in pseudo-static rules?

WBOY
WBOYOriginal
2016-09-01 00:20:121502browse

The following form rules exist:
/index.php?m=search&c=index&s=1&t=1&k=Keywords
I want to forward the path to
/search?s=1&t=1&k=Keywords

in a pseudo-static form

You can only get one parameter value using the following method
RewriteCond %{QUERY_STRING} ^k=(.+)$
RewriteRule ^search$ /index.php?m=search&c=index...&k=%1

If you use the following method to obtain multiple parameters, the order of the parameters is fixed. Once the order is changed, it will not work.
RewriteCond %{QUERY_STRING} ^k=(.+)&s=(.+)&c=(.+)$
RewriteRule ^search$ /index.php?m=search&c=index...&k=%1&s=%2&c=%3

If you use the following method, there is a security risk, and the number of parameters cannot be limited
RewriteRule ^search$ /index.php?m=search&c=index [L,QSA]

Please ask the experts for any good solutions?

Reply content:

The following form rules exist:
/index.php?m=search&c=index&s=1&t=1&k=Keywords
I want to forward the path to
/search?s=1&t=1&k=Keywords

in a pseudo-static form


You can only get one parameter value using the following method
RewriteCond %{QUERY_STRING} ^k=(.+)$

RewriteRule ^search$ /index.php?m=search&c=index...&k=%1


If you use the following method to obtain multiple parameters, the order of the parameters is fixed. Once the order is changed, it will not work.
RewriteCond %{QUERY_STRING} ^k=(.+)&s=(.+)&c=(.+)$

RewriteRule ^search$ /index.php?m=search&c=index...&k=%1&s=%2&c=%3


If you use the following method, there is a security risk, and the number of parameters cannot be limited

RewriteRule ^search$ /index.php?m=search&c=index [L,QSA]

Please ask the experts for any good solutions?

Parameters such as k s c

are still used as regular matches, such as: 🎜
<code>RewriteCond %{QUERY_STRING} ^([a-z]+)=(.+)&([a-z]+)=(.+)&([a-z]+)=(.+)$
RewriteRule ^search$ /index.php?m=search&c=index...&%1=%2&%3=%4&%5=%6</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn