php - PHP/CodeIgniter 有什么方法可以读取 URL,就像 site.com/#/xyz ...?

标签 php javascript url codeigniter fragment

基本上我有一个主要基于 Ajax 的站点。当您加载结果时,它会通过 Ajax 显示,并且 URL 地址栏会从 mysite.com 更改为 mysite.com/#xyz/A_Random_Title

A_Random_Title 是加载内容的 SEO 友好格式标题,但重要的部分是 #xyzxyz为加载结果的ID,用于查询数据库。

CodeIgniter 有什么方法可以读取当前的 URL 吗?我的意思不是在页面加载后阅读它,而是阅读对它的请求...希望这是有道理的!

谢谢!

jack

最佳答案

不行,它只对浏览器可用,所以你必须用 Javascript 来处理它。服务器无法读取。

解释:
基本上,页面 URL 的哈希部分(# 符号后面的部分)仅由浏览器处理——浏览器永远不会将其传递给服务器。遗憾的是,这是 HTML 标准的一部分,无论您是否使用 IE 或任何其他浏览器(以及 PHP 或任何其他服务器端技术)都是一样的。

这是 Wikipedia 是这样说的:

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server. When an agent (such as a Web browser) requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the fragment value. In the most common case, the agent scrolls a Web page down to the anchor element which has an attribute string equal to the fragment value. Other client behaviors are possible

关于php - PHP/CodeIgniter 有什么方法可以读取 URL,就像 site.com/#/xyz ...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3627064/

相关文章:

php - 将数据库中的数据显示给特定用户(使用角色?)

java - 托管一个基于java的服务器

php - 如何在 PHP 中检查域名是否为 CNAME

c# - 在 ASP.NET C# 中从 URL 中提取子目录名称

php - Silex SwiftMailer 在执行时不建立 SMTP 连接

php - 如何使用纪元时间查看有多少用户在线?

javascript - 禁用的按钮颜色在 IE9 中未正确呈现

javascript - 有什么方法可以声明事件对象而不是在函数的参数中?

javascript - expect 中 toContain() 的实际用途是什么?

PHP - 检查 url 是否有效