gpt4 book ai didi

jquery - htaccess 和哈希隐藏

转载 作者:行者123 更新时间:2023-12-01 04:17:13 24 4
gpt4 key购买 nike

下午,

是否可以在 htacces 重定向中添加类似 http://example.com/portfolio 的规则至 http://example.com/index.php#portfolio而不在浏览器的 URL 字段中显示最后一个地址?

我知道 hast 不会发送到服务器,但必须有某种方法来掩盖这些丑陋的 URL..

可能与问题相关或不相关,但我有以下 jQuery 代码

if(history.pushState){
history.pushState(null,null,'#'+$(this).attr('class'));
}else{
location.hash = '#'+$(this).attr('class');}
}

if(window.location.hash){
var hash = window.location.hash.substring(1);
if(jQuery.browser.webkit){
$('html,body').animate({scrollTop:$('#'+hash).offset().top-2*88},'slow');
}else{
$('html,body').animate({scrollTop: $('#'+hash).offset().top-3*88-10},'slow');}
}
}

提前感谢您提供任何解决方案。

最佳答案

I know the hast doesn't get send to the server, but there must be some kind of way to mask these ugly URLs..

没有。通过“从浏览器中屏蔽它”,这意味着浏览器不知道它请求的 URL 已在服务器端被破坏。它认为它已经请求了http://example.com/portfolio,因此这就是它在地址栏中显示的内容。

如果您想在浏览器中隐藏#portfolio片段,那么该片段将变得完全无用。浏览器是客户端和服务器之间唯一可以利用此类片段的实体,但浏览器看不到它,因为服务器隐藏了它。服务器对该片段的使用为零,因此向浏览器隐藏了该片段。如果没有某种框架(隐藏 URL)或一些 JavaScript 技巧来更改地址栏中的内容,您就无法让浏览器加载与地址栏上显示的 URL 不同的 URL。

如果服务器内部将 /portfolio 重写为 /index.php#portfolio,则该片段将立即被丢弃。 index.php 的执行并不知道它存在,因为只有浏览器关心该片段。

如果您不希望网址中出现片段,则应该重新设计内容的交付方式。

关于jquery - htaccess 和哈希隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13938487/

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