帮忙重写网址

发布于 2024-11-02 08:28:47 字数 377 浏览 0 评论 0原文

可能的重复:
请在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我最亲爱的 2024-11-09 08:28:47

www.site.com/12 设置的问题在于,它使得操作起来有点棘手,就好像您想要实际添加一个名为 1000 的物理页面一样设置可能无法正常工作(这也可能取决于多视图)。相反,我会避开这一点并执行类似的操作:

www.site.com/room/12www.site.com/room/id/12

>.htaccess 重定向将类似于:

RewriteRule ^room/id/(.*)$ room/doorstep.php?page_id=$1 [L]

这应该为您提供在路上演出所需的示例。


编辑

可能更好的是只匹配一个数字:

RewriteRule ^room/id/([0-9]+)$ room/doorstep.php?page_id=$1 [L]

只有传递了一个数字,它才会返回 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 called 1000 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 or www.site.com/room/id/12

The .htaccess redirect for that would be something like:

RewriteRule ^room/id/(.*)$ room/doorstep.php?page_id=$1 [L]

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:

RewriteRule ^room/id/([0-9]+)$ room/doorstep.php?page_id=$1 [L]

Which would only return true if a number was passed, since that is what your ID's seem to consist of.

oО清风挽发oО 2024-11-09 08:28:47

假设您已在 Apache 中设置了 mod_rewrite,您可以在 .htaccess 中执行以下操作

RewriteEngine On
RewriteRule ^([0-9]+)$ room/doorstep.php?page_id=$1 [L]

Assuming you've got mod_rewrite set up in Apache, you can do the following in your .htaccess

RewriteEngine On
RewriteRule ^([0-9]+)$ room/doorstep.php?page_id=$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文