帮忙重写网址
可能的重复:
请在 php 中重写 URL
我希望访问者通过输入 来访问该页面www.site.com/12
而不是 www.site.com/room/doorstep.php?page_id=12
ID 太多,所以我无法创建文件夹。 执行此操作需要什么代码? 我试图通过 .htaccess 来做到这一点,但我没有成功。 请帮我解决这个问题。
丹尼斯.
Possible Duplicate:
Please URL Rewrite in php
I would like visitors to access the page by typing www.site.com/12
instead of www.site.com/room/doorstep.php?page_id=12
The IDs are many so i cannot create folders.
What is the code needed to do this?
I am trying to do this through .htaccess
but I have not been successfull.
Please help me with this.
Dennis.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
www.site.com/12
设置的问题在于,它使得操作起来有点棘手,就好像您想要实际添加一个名为1000
的物理页面一样设置可能无法正常工作(这也可能取决于多视图)。相反,我会避开这一点并执行类似的操作:www.site.com/room/12
或www.site.com/room/id/12
>.htaccess 重定向将类似于:
这应该为您提供在路上演出所需的示例。
编辑
可能更好的是只匹配一个数字:
只有传递了一个数字,它才会返回 true,因为这就是你的 ID 的组成部分。
The problem with the
www.site.com/12
setup, is it makes it a bit tricky to do, as if you want to actually add a physical page called1000
your setup may not work right (which may also depend on multiviews). Instead I would steer away from that and do something like:www.site.com/room/12
orwww.site.com/room/id/12
The
.htaccess
redirect for that would be something like:That should give you the example you need to get the show on the road.
EDIT
What might even be better is just match a number:
Which would only return true if a number was passed, since that is what your ID's seem to consist of.
假设您已在 Apache 中设置了
mod_rewrite
,您可以在.htaccess
中执行以下操作Assuming you've got
mod_rewrite
set up in Apache, you can do the following in your.htaccess