mod_rewrite RewriteCond 和查询字符串
最近,我一直在为客户做一个小项目。我正在考虑使用 WordPress 风格的漂亮 URL 格式。我在 google 上搜索了很多,发现了 Apache 的 mod_rewrite 和 RewriteRule
、RewriteCond
。但没有找到任何可以处理随机参数的示例。例如:
/index.php?param=1
→/index/param/1
/index.php?foo=bar&hour=1&mins= 12
→/index/foo/bar/hour/1/mins/12
/index.php?page=login&attempt=2
→/index/page/login/attempt/2
或类似的内容。
正如您所看到的,参数不是固定的。有办法实现这个目标吗?任何帮助将不胜感激。
谢谢
recently, I have been working on a small project for a client. I was thinking about using a wordpress style pretty URL format. I googled around a lot and came accross Apache’s mod_rewrite and RewriteRule
, RewriteCond
. But didn't find any example which can handle random of parameters. For example:
/index.php?param=1
→/index/param/1
/index.php?foo=bar&hour=1&minutes=12
→/index/foo/bar/hour/1/minutes/12
/index.php?page=login&attempt=2
→/index/page/login/attempt/2
or something similar.
As you can see parameters are not fixed. Is there anyway to achieve this? Any help would be greatly appreciate.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数 CMS 使用 PHP 来完成此操作。
.htaccess
PHP
然后你就得到了 url 各部分的数组,你可以根据需要处理它们。
Most CMS does this with PHP.
.htaccess
PHP
Then you've got an array of the parts of the url, and you can process them as you want.