gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:38:21 28 4
gpt4 key购买 nike

基本上我有一个主要基于 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com