删除“#”来自网址

发布于 2024-12-14 22:34:39 字数 941 浏览 1 评论 0原文

更新

我不明白如何进行这项工作,所以我希望你知道,因为我没有找到更多解决方案:

我已经在 wordpress 中使用 window.location.hash 实现了 jquery 循环来创建一个单独的每张幻灯片的网址(此处示例 http://jquery.malsup.com/cycle/perma.html< /a>)

现在我有一个indez 包含一些不同类别的选定照片,这些照片可与 localhost/prueba/#men/#work61localhost/prueba/#women/#work15 等哈希一起使用。诀窍是我还有类别 /men/ 和照片 #work61 永久导致索引可能会改变,但类别中的照片确实不会改变。所以我需要的是在不重新加载的情况下更改网址,从 /#men/ 更改为 /men/,如果他们共享链接,他们将始终转到正确的照片和部分(我解释得清楚吗?)

我一直在测试多种到达方式,使用history.js,甚至使用过道Pushestate,但我没有找到正确的解决方案。最近我用 htaccess 做了这个,它正是我所需要的

Options +FollowSymLinks
RewriteEngine On
RewriteBase /prueba/
RewriteRule ^([^/]+)/([^/]+)/$ $1/#$2 [NE,R]

这将我从 localhost/prueba/men/work61 更改为 localhost/prueba/men/#work61 但如果我尝试将哈希添加到第一个文件夹(#men),也只有在有人直接放置链接时才有效

知道吗?提前致谢

UPDATED

I didn't understand how to make this work so I hope you know because I didn't found more solutions:

I have implemented jquery cycle in wordpress with the window.location.hash to make an individual url from each slide (example here http://jquery.malsup.com/cycle/perma.html)

Now I have an indez with some selected photos of differents categories that works with hashes like localhost/prueba/#men/#work61, localhost/prueba/#women/#work15, etc...the trick is that I have also the category /men/ and the photo #work61 permanetly cause the index may change but not the photo in the category indeed. So what I need is change the url without reloading from /#men/ to /men/ and if they share a link they will always go to the right photo and section (did I explain it well ?)

I have been testing many ways to arrive, with history.js and even with the aisle Pushestate but I didn't found the right solution. Lately I have made this with htaccess and it's closely what I need

Options +FollowSymLinks
RewriteEngine On
RewriteBase /prueba/
RewriteRule ^([^/]+)/([^/]+)/$ $1/#$2 [NE,R]

This changes me from localhost/prueba/men/work61 to localhost/prueba/men/#work61 but if I tried to add a hash to the first folder (#men), an also only work if somebody put the link directly

Any idea? Thanks in advance

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

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

发布评论

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

评论(1

女中豪杰 2024-12-21 22:34:39

我认为您需要了解 URI 规范,第 3.5 节 https://www. rfc-editor.org/rfc/rfc3986#section-3.5。本质上,在显示 HTML 文档的 Web 浏览器上下文中,URI 片段(在 # 之后)指的是资源(页面)的子集。

基本上,如果您从 URL 中删除了 #,您将不会引用同一资源的不同子集,而是完全引用另一个资源。因此将请求另一页。

I think you need to understand the URI specification, section 3.5 https://www.rfc-editor.org/rfc/rfc3986#section-3.5. Essentially, in the context of a web browser displaying HTML documents, the URI fragment (after the #) refers to a subset of the resource (page).

Basically if you removed the # from your URL, you will not be referring to a different subset of the same resource, but another resource entirely. So another page will be requested.

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