gpt4 book ai didi

apache 将一个目录下的所有hash tag 改写为slash tag

转载 作者:行者123 更新时间:2023-12-04 04:33:53 29 4
gpt4 key购买 nike

如何将一个目录下的所有hash tag重写为slash tag? ( Apache )

http://www.domain.com/company/index#about => http://www.domain.com/company/index/about
http://www.domain.com/company/article#123456 => http://www.domain.com/company/article/123456
http://www.domain.com/company/events#October => http://www.domain.com/company/events/October

所以,所有在 /company/ 中的页面,重写 # => /

$(window).on('hashchange', function() {
//
}

最佳答案

通常,所有浏览器都会从对服务器的请求中排除片段部分 (#)。如果你真的想这样做,你必须在调用服务器之前重写url

function addHashtag2Pathname(url){
var a = document.createElement('a');
a.href = url;
if (a.pathname.substr(-1) != "/")
a.pathname = a.pathname + '/';
a.pathname += a.hash.replace(/^#/,'');
a.hash = '';
return a.href.replace(/#$/,'');
}

您可以在此处查看此功能的运行情况
http://jsfiddle.net/bknE4/43/

实际上我没有在下面尝试过,但它应该可以工作......
$(window).on('hashchange', function() {
var newurl = addHashtag2Pathname(location.href);
location.href = newurl;
})

关于apache 将一个目录下的所有hash tag 改写为slash tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20097983/

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