这个问题似乎很容易,但搜索后3天,我就放弃了。我想,我会在这里找到它,它似乎也有类似的人,但它并没有这个东西的工作。
目前我有了基于他的previos JS / AJAX驱动的网站一个非常先进的营销客户。他的网站所有的返回链接就像是
服务器 /#!链接
我建立了一个字preSS的网站,我需要让适当的交叉链接打开的网页。
但是,如果我得到这个链接
服务器 /#!链接
我得到以下网址当Word preSS过程中,它
服务器/
我走这条唯一的出路,或者至少是只有我自己知道是用字preSS做到这一点,但是这似乎并不容易。
我有以下脚本,可以添加#!但需要删除(刚发现它的地方)
< PHP
$ webSiteUrl = get_bloginfo('链接')/。
$ PAGEURL ='HTTP';
如果($ _ SERVER [HTTPS] ==ON){
$ PAGEURL =S。
};
$ PAGEURL =://。
如果($ _ SERVER [SERVER_PORT]!=80){
。$ PAGEURL = $ _ SERVER [SERVER_NAME]:。$ _ SERVER [SERVER_PORT] $ _ SERVER [REQUEST_URI];
} 其他 {
。$ PAGEURL = $ _ SERVER [SERVER_NAME] $ _ SERVER [REQUEST_URI]。
};
如果($ webSiteUrl!= $ PAGEURL){
$ pageHash = SUBSTR($ PAGEURL,strlen的($ webSiteUrl)的strlen($ PAGEURL));
标题(位置:#!/。$ webSiteUrl $ pageHash);
出口;
};
?>
由于娇气ossifrage 我几乎没有。 我用这个脚本时提供的曾与条件的一些问题
如果(''== window.location.hash和放大器;!&放大器;#!'== window.location.hash){
散列= location.hash.match(/ ^#(*)/!。)[1];
/ * ...做点什么散,像重定向到* /
/ *另一个网页,或加载网页内容通过AJAX。 * /
/ *如果你想要做的是消除一切* /
/ *以`#网址开始',那么试试这个:* /
location.href = location.protocol +'//'+ location.host + location.pathname;
}
这似乎工作,但我得到的根页。
例如。我打开
myweb.com /#!thisone
和我得到
myweb.com/
和公正的总结所以有人可以节省大量的时间 - 工作脚本
如果(''== window.location.hash和放大器;!&安培;'!'== window.location.hash){
散列= location.hash.match(/ ^#(*)/!。)[1];
/ * ...做点什么散,像重定向到* /
/ *另一个网页,或加载网页内容通过AJAX。 * /
/ *如果你想要做的是消除一切* /
/ *以`#网址开始',那么试试这个:* /
location.href = location.protocol +'//'+ location.host + location.pathname +/+散;
}
解决方案
您不能这样做在PHP中,因为服务器永远不会看到URL(即#符号和一切跟随它)的片段组成部分
您将不得不使用客户端JavaScript来代替。事情是这样的可能:
如果/^#!/.test(location.hash){
散列= location.hash.match(/ ^#(*)/!。)[1];
/ * ...做点什么散,像重定向到* /
/ *另一个网页,或加载网页内容通过AJAX。 * /
/ *如果你想要做的是消除一切* /
/ *以`#网址开始',那么试试这个:* /
location.href = location.protocol +'//'+ location.host + location.pathname;
}
编辑::如果我理解正确的话,你想放的重定向URL末尾的哈希值。这是很容易做到。只是上面的code中的倒数第二行改为
`location.href = location.protocol +'//'+ location.host + location.pathname +/+散;`
附加'/'可能是不必要的;我将离开你弄清楚细节: - )
The question seems to be easy but after 3 days of searches I gave up. I thought that I will find it here and it seems to have similar ones but it doesn't work for this stuff.
Currently I have a customer that has a really advanced marketing based on his previos JS/AJAX driven website. All the back link to his website is like
SERVER /#! LINK
I have built a wordpress website and I need so that cross links open pages properly.
But if I get this link
SERVER /#! LINK
I get following URL when Wordpress process it
SERVER /
I have explored that the only way, or at least the only I know is to do it with wordpress but that doesn't seems to be easy.
I have following script that can ADD #! but is need to remove (just found it somewhere)
<?php
$webSiteUrl = get_bloginfo('url')."/";
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
};
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
};
if($webSiteUrl!=$pageURL){
$pageHash = substr($pageURL, strlen($webSiteUrl), strlen($pageURL));
header("location:".$webSiteUrl."#!/".$pageHash."");
exit;
};
?>
Thanks to squeamish ossifrage I am almost there. I used this script as the one you provided had some issues with condition
if ('' !== window.location.hash && '#!' !== window.location.hash) {
hash = location.hash.match(/^#!(.*)/)[1];
/* ... do something with hash, like redirecting to */
/* another page, or loading page content via AJAX. */
/* If all you want to do is remove everything from */
/* the URL starting with `#!', then try this: */
location.href = location.protocol+'//'+location.host+location.pathname;
}
It seems to work but I get root page.
e.g. I open
myweb.com/#!thisone
and I get
myweb.com/
AND JUST TO SUMMARIZE so somebody can save lots of time - working script is
if ('' !== window.location.hash && '!' !== window.location.hash) {
hash = location.hash.match(/^#!(.*)/)[1];
/* ... do something with hash, like redirecting to */
/* another page, or loading page content via AJAX. */
/* If all you want to do is remove everything from */
/* the URL starting with `#!', then try this: */
location.href = location.protocol+'//'+location.host+location.pathname+'/'+hash;
}
解决方案
You can't do this in PHP because the the server will never see the fragment part of the URL (i.e., the # symbol and everything that follows it).
You'll have to use client-side Javascript instead. Something like this perhaps:
if /^#!/.test(location.hash) {
hash = location.hash.match(/^#!(.*)/)[1];
/* ... do something with hash, like redirecting to */
/* another page, or loading page content via AJAX. */
/* If all you want to do is remove everything from */
/* the URL starting with `#!', then try this: */
location.href = location.protocol+'//'+location.host+location.pathname;
}
EDIT: If I understand correctly, you want to put the hash value at the end of the redirect URL. That's quite easily done. Just change the penultimate line of the above code to
`location.href = location.protocol+'//'+location.host+location.pathname+'/'+hash;`
The additional '/' may be unnecessary; I'll leave you to figure out the details :-)