【发布时间】:2012-10-13 09:32:38
【问题描述】:
我正在 wordpress 上建立一个带有 hashchange 的网站,一切正常。它只是将一个 single.php 模板文件加载到一个 div 中。
问题是我仍然可以访问我的单个网址 (http://www.mydomain.com/my-single-post)。由于它没有任何头部和样式标签,我不希望人们去那里。 google 也选择了直接链接,因为我使用 href 属性将内容加载到 div 中。
所以我的问题是:
如果有人在论坛中点击链接,比如http://www.mydomain.com/my-single-post,是否可以立即将他重定向到http://www.mydomain.com/#my-single-post?我研究过它与.htaccess有关,但我也有页面,我不希望页面名称前面有哈希。
编辑
我有一个小更新。如果这段代码从url中删除了hash-tag并重定向到一个非hash url,那么如何将这段代码反过来呢?
var current_hash = location.hash;
current_hash = current_hash.replace(/#/,'');
if(current_hash.length>1){
// we have something after the #. redirect as if the # wasn't there.
window.location.href=current_hash;
}
【问题讨论】:
标签: jquery ajax wordpress redirect