0

I have a link that needs to be redirected elsewhere. My CMS (WP Engine) typically handles redirects, however, I am stuck with the following.

(placeholder domain for client privacy)

LINK A: www.test.com/#/contacts

LINK B: www.test.com/another-page

How can I successfully redirect A to B?

Is there any special steps (CMS related or not) that I need to do to make a URL with a hash symbol redirect?

  • It is possible to do with JavaScript only. https://stackoverflow.com/questions/3664257/why-the-hash-part-of-the-url-is-not-in-the-server-side – Andrei B Mar 29 '18 at 12:42

1 Answers1

2

So you only want to forward urls with #? If it's just one page, you can just string match the current url with the page you want to redirect.

add_action( 'template_redirect', function(){
    $current_page = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

    if( strpos( $current_page, '/#/contact' ) !== false ){
        wp_redirect( site_url( '/another-page/' ) );
        exit;
    }
});

If you have multiple pages, and the permalinks are /#/slug, you can use a redirection plugin such as Content Mask, Simple 301 Redirects, or Page Links To.

Xhynk
  • 13,513
  • 8
  • 32
  • 69