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
Release: 2016-09-01 00:20:12
Original
1510 people have browsed it

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template