简体   繁体   English

带有磅的Java重定向在Wordpress中不起作用

[英]Javascript Redirects with Pound not working in Wordpress

I have a link to my site on a very popular but now dead website. 我在一个非常流行但现在已经失效的网站上链接到我的网站。 The link is incorrect, so I'd like to redirect users to the correct page when they visit. 链接不正确,因此我想在用户访问时将用户重定向到正确的页面。 I'm using Wordpress for my content. 我正在使用Wordpress作为内容。

The problems lie in the fact that the incorrect URL that the website lists is http://www.senntenial.com/#!mysterium/cj6d . 问题在于网站列出的URL错误是http://www.senntenial.com/#!mysterium/cj6d From my research, I cannot do a 301 redirect in my htaccess, since this URL has a # sign, and is client only. 根据我的研究,我无法在htaccess中执行301重定向,因为此URL具有#符号,并且仅用于客户端。

So, I tried creating the following script in my header.php file. 因此,我尝试在header.php文件中创建以下脚本。

if (window.location == 'http://www.senntenial.com/#!mysterium/cj6d'){
    window.location = 'http://www.senntenial.com/mysterium/';
}

I would think this would have worked, but it doesn't. 我认为这是可行的,但事实并非如此。 To identify the problem, I tried simply inputting window.location = 'http://www.senntenial.com/mysterium/'; 为了确定问题,我尝试仅输入window.location = 'http://www.senntenial.com/mysterium/'; Which worked correctly, meaning my problem lies in identifying the current window location. 哪个工作正常,这意味着我的问题在于确定当前窗口位置。

How can I accomplish this? 我该怎么做? I assume Wordpress has a funky way of going about things with URL's to make them easier to read that may be messing with my code. 我认为Wordpress具有处理URL问题的一种时髦方式,使它们更易于阅读,这可能会干扰我的代码。

(PS, I tried WP extensions like EPS 301 redirect to no avail.) (PS,我尝试将EPS 301之类的WP扩展重定向到无济于事。)

Also, the mysterium page is static HTML, and not involved with Wordpress' CMS. 另外,神秘页面是静态HTML,与Wordpress的CMS不相关。

There's window.location.hash which gives the fragment part of the current URI. window.location.hash ,它给出了当前URI的片段部分。 So something like 所以像

if(window.location.hash=="#!mysterium/cj6d"){
  window.location = 'http://www.senntenial.com/mysterium/';
}

Might work. 可能会工作。 You could also use window.location.href which contains the full URI but then you need to check with and without www. 您还可以使用包含完整URI的window.location.href ,但随后需要检查是否带有www.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM