I recently wrote an IP for the geographic location of the online API using PHP and java. Since I wanted to make my URL look more beautiful, I used the htaccess Rewrite syntax to rewrite the URL."The situation was finally solved. I would like to share it here: The effect I want to achieve is to
1 2 3 |
Api.php?format=js&ip=10.22.56.0 Rewritten to api.js?ip=10.22.56.0 Api.php?format=json&ip=10.22.56.0 rewritten as api.json?ip=10.22.56.0 |
So it's easy to write the following rules:
1 |
RewriteRule api.(txt|html|json|js)?(.*)$ api.php?format=$1&$2 [L] |
And then it can't always achieve the relevant effect. The initial reason is that rewrite can't match QUERY_STRING with a question mark, and finally it succeeds with the following rules:
1 |
RewriteRule api.(txt|html|json|js)(.*)$ api.php?format=$1&%{QUERY_STRING} [L] |
%{variable name} can get the requested parameter
This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!
Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/htacess-rewriterule-contain-problem-of-draw-2.html
No Comment