简体   繁体   English

使用/#/重定向URL

[英]Redirect a URL with /#/

Our current website is built using AngularJS and as a result has URLs with /#/ in them such as http://www.website.com/#/termsofuse 我们当前的网站是使用AngularJS构建的,因此其中包含带有/#/ URL,例如http://www.website.com/#/termsofuse

Short-sightedly, the URL for terms or use has been hard coded into a mobile application and although this has been changed, some users still have older versions. 短视而言,术语或用法的URL已被硬编码到移动应用程序中,尽管已进行了更改,但某些用户仍具有较旧的版本。

We're moving to a WordPress site (running on Azure) and the new URL for terms of use is http://www.website.com/termsofuse 我们将转到WordPress网站(在Azure上运行),使用条款的新URL为http://www.website.com/termsofuse

The issue is that I want to redirect to the new URL if the old URL is used (from the app where it is hard coded in older versions) but I can't find a way to do this with the /#/ in the URL (otherwise I could use HTML/JS at the old URL to redirect). 问题是,如果使用旧的URL(从旧版本中使用硬编码的应用程序中),我想重定向到新的URL,但是我找不到在URL中使用/#/做到这一点的方法(否则,我可以在旧的URL上使用HTML/JS进行重定向)。

I have tried searching for solutions on Google and here but although I'm sure someone has had this problem, I'm finding it hard to define the search terms in order to get valuable results. 我曾尝试在Google和此处搜索解决方案,但是尽管我确定有人遇到了这个问题,但我发现很难定义搜索字词才能获得有价值的结果。

I also considered posting this on WordPress stackexchange but it is not really a WordPress question, I'm assuming I'll need to use some other method. 我也考虑过将其发布在WordPress stackexchange上,但这并不是一个真正的WordPress问题,我假设我需要使用其他方法。

Appreciate any ideas or advice. 感谢任何想法或建议。 Thanks in advance. 提前致谢。


So far I have learnt from responses that I probably need a JS solution and based on that I have found the below which looks similar (at least shows me how to isolate the fragment after the URL). 到目前为止,我已经从响应中了解到我可能需要一个JS解决方案,并且基于此,我发现下面的内容看起来很相似(至少向我展示了如何隔离URL后的片段)。 Since my issue is very specific, and I only need to look for the specific fragment #/termsofuse could I use this code (with midifications) to look for that string and redirect based on that? 由于我的问题非常具体,我只需要查找特定的片段#/ termsofuse,是否可以使用此代码(带有中间标记)来查找该字符串并基于该字符串进行重定向?

Checking URL fragment for a keyword 检查关键字的URL片段

Sadly, this is not possible as everything after the # doesn't get sent to the server. 可悲的是,这是不可能的,因为#之后的所有内容都不会发送到服务器。

What many people do in this sort of situation is to use a javascript/ajax solution to load the page. 在这种情况下,许多人要做的是使用javascript / ajax解决方案加载页面。

By your description, as your new web site is built on WordPress without AngularJs. 根据您的描述,因为您的新网站是基于WordPress的,而没有AngularJs。

So it hardly could approach your need in a traditional way. 因此,几乎不可能以传统方式满足您的需求。 As hashtag # is a client symbol which is never passed on serve, so IIS on Azure will not get the portion after # of the URL, also URL rewrite module won't see it too. 正如主题标签#是决不会在服务传递客户端象征,所以IIS在Azure上后不会得到部分#的URL,还URL重写模块将无法看到这一点。

So if possible to modify home page of your WordPress site, here is a workaround with using JavaScript get the portion after # of the URL and redirect to the right URL. 因此,如果可能的话,可以修改WordPress网站的首页,这是一种使用JavaScript的变通方法,即使用JavaScript获取URL #后的部分并重定向到正确的URL。 Here is the code snippet: 这是代码片段:

(function () { console.log(window.location.href); var url = window.location.href; params = url.split('#'); console.log(params); if(params[1]){ window.location.href = params[1]; } })();

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

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