mod_rewrite 和explode("/", $_SERVER['REQUEST_URI'])

发布于 2025-01-05 22:12:09 字数 94 浏览 3 评论 0 原文

如果我的路由系统中已经有explode("/", $_SERVER['REQUEST_URI']),为什么我需要mod_rewrite 和其他apache url 重写设置?

If I already have the explode("/", $_SERVER['REQUEST_URI']) in my routing system, why do I need the mod_rewrite and other apache url rewriting settings?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

我恋#小黄人 2025-01-12 22:12:09

当您没有 mod_rewrite 和 .htaccess 文件来指定如何处理像 domain.com/foo/bar 这样的 url 时,服务器会搜索文件夹 foo,然后文件夹 bar 查找索引文件以显示给用户。

如果您需要在脚本中处理它,您需要首先将用户重定向到您的基本脚本,然后在查询字符串上使用explode,然后继续下一步。这就是 mod_rewrite 和 .htaccess 发挥作用的地方。

When you do not have mod_rewrite and the .htaccess file to specify what to do with an url like domain.com/foo/bar the server searches for the folder foo and then the folder bar to look for the index file to show the user.

If you need it to be handled within your script, you need to first redirect the user to your base script then use explode on your query string and then proceed further. This is where mod_rewrite and .htaccess come into play.

羁客 2025-01-12 22:12:09

当 URL 结构与目录结构不同时,要拥有干净的 URL。

几点:

  • 规范网址
  • 规范主机名
  • 移动文档根目录
  • 在多个目录中搜索页面
  • 根据 URL 部分设置环境变量
  • 内容处理
  • 访问限制

有关更多信息,请阅读此处: URL 重写指南

To have Clean URLs, When URL structure is not same as the directory structure.

Some points:

  • Canonical URLs
  • Canonical Hostnames
  • Moved DocumentRoot
  • Search pages in more than one directory
  • Set Environment Variables According To URL Parts
  • Content Handling
  • Access Restrictions

For more read here: URL Rewriting Guide

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文