1

Our current website is built using AngularJS and as a result has URLs with /#/in them such as 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.

We're moving to a WordPress site (running on Azure) and the new URL for terms of use is 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).

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.

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.

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). 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?

Checking URL fragment for a keyword

Community
  • 1
  • 1
petebulley
  • 13
  • 3
  • 1
    possible duplicate of ['hash' url rewrite in .htaccess](http://stackoverflow.com/questions/15133023/hash-url-rewrite-in-htaccess) – baao Sep 07 '15 at 13:15
  • I wonder if it would be possible to have some logic on the error page it directs to, to read the referrer address... (I've no idea, its a passing thought!) – Michael B Sep 07 '15 at 13:29
  • Thanks @michael this looks like a similar issue but having read through and the linked posts I'm still unsure how to solve my issue. – petebulley Sep 08 '15 at 07:06
  • Thanks for the idea @MichaelB but it looks like since everything after the # is ignore, the website will load without error at the root domain. – petebulley Sep 08 '15 at 07:09
  • So your new web site is a WordPress site without Angular Js? – Gary Liu Sep 08 '15 at 07:16
  • @GaryLiu-MSFT that's correct – petebulley Sep 08 '15 at 07:21
  • My only other thought, though it does raise the complexity significantly, would be some sort of reverse proxy server infront, something like squid that can redirect those pages (at least I presume something like squid could) – Michael B Sep 08 '15 at 09:30
  • My other thought is that even though it is ignored on the routing, maybe it is in a header somewhere? if you could pipe a test into AngularJS' version of PHPInfo (I don't know anything about angular!) you might be able to test for it there – Michael B Sep 08 '15 at 09:34

2 Answers2

1

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.

baao
  • 71,625
  • 17
  • 143
  • 203
0

By your description, as your new web site is built on WordPress without 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.

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. 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]; } })();

Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • Thanks this is a great solution to the general problem. The only issue for my specific need is that I only want this to happen for one specific instance ../#/termsofuse and not for other instances such as where I am using anchors. I implemented your solution and it worked for the URL redirect issue but when I use anchors on the site they will now not work - is there a way I can modify your snippet to work for just one variable? – petebulley Sep 08 '15 at 08:15
  • We can detect whither it's an anchor before redirecting `if(params[1]=='/termsofuse'){ window.location.href = params[1]; }` – Gary Liu Sep 08 '15 at 08:32