PHP:URL 格式 www.mysite.com/users/33
我见过这样的 URL,我只是想知道它们是如何使用的。
到目前为止,我一直使用 www.mysite.com/users/?id=33
如何使用其他格式?
I've seen URL's like this around and I'm just wondering how it is they are used.
Until now I've been using www.mysite.com/users/?id=33
How can I use the other format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Paul Peelan 的答案是正确的,如果有点冗长:-) 将其放入站点根目录的 .htaccess 文件中:
这将匹配 /users/33、/users/1、/users/12345 等并重定向到 /users/ ?id=12345。
这要求您的 Apache 配置启用了
mod_rewrite
引擎。有关详细信息,请参阅mod_rewrite 文档。Paul Peelan's answer is correct if a little verbose :-) Put this in your .htaccess file in the root of your site:
This will match /users/33, /users/1, /users/12345 etc and redirect to /users/?id=12345.
This requires that your Apache configuration has the
mod_rewrite
engine enabled. See the mod_rewrite docs for further information.您将必须使用“mod-rewrite”和例如.htaccess 文件。
然后 Apache 将根据您在 .htaccess 文件中的设置发送 URL。
例如:
各种重写规则。
问候,
保罗
You will have to use the "mod-rewrite" and e.g. an .htaccess file.
Apache will then send the urls according to your settings in the .htaccess file.
E.g.:
Various rewrite rules.
Regards,
Paul
我知道您已经选择了这个问题的答案,但这非常有用。 PHP 框架 Codeigniter 默认允许您使用这样的 URL。我发现用这种方式进行 URL 重写要容易得多。有关此内容的更多信息,包括代码示例,请访问 http://codeigniter.com/user_guide /general/urls.html
I know you have already selected an answer for this question, but this is quite useful to know. The PHP framework Codeigniter allows you to use URLs like this by default. I found it a lot easier to do URL rewriting this way. Further information about this, including code samples, can be found at http://codeigniter.com/user_guide/general/urls.html