使用 mod_rewrite 创建 RESTful URL 格式
我有一个网页 http://mydomain.com/form.php?id=123
, 我需要保留旧功能的这种格式,并实现新功能,以便用户可以像 http://mydomain.com/123
一样访问此页面。
- 因此客户端将看到这个
http://mydomain.com/123
。 - 服务器将理解为旧版本
http://mydomain.com/form.php?id=123
。
这样我就不必改变旧的功能。 我知道这可以通过 HTaccess 规则来完成。但不知道怎么做。 请帮忙。谢谢。
I have a webpage http://mydomain.com/form.php?id=123
,
I need to keep this format for old functionality , and to implement a new functionality so the user could access this page like this http://mydomain.com/123
.
- So the client will see this
http://mydomain.com/123
. - And the server will understand as old version
http://mydomain.com/form.php?id=123
.
So this way I don't have to change the old functionality.
I know that this can be accomplished through HTaccess rule. but don't know how.
Please help. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能应该为您处理
!-f
排除任何已经存在的文件(因此直接点击/form.php不会被重写),!-d
排除任何目录存在(因此,如果您的网站上有真正的/123/
,它将不会被重写),否则将其他所有内容重定向到您的 form.php 脚本。如果您只想重定向纯数字 URL,那么上面的 mhitza 评论就是您想要的。
This should probably handle it for you
!-f
excludes any files which already exist (so hitting /form.php directly will not get rewritten),!-d
excludes any directories which exist (so if you have a real/123/
on your site it won't get rewritten), and otherwise redirects everything else to your form.php script.If you only want to redirect purely numeric URLS, then mhitza's comment above is what you want.