# Internal Redirect

**URL:** https://discourse.roots.io/t/internal-redirect/4925
**Category:** sage
**Created:** 2015-10-07T22:14:27Z
**Posts:** 3

## Post 1 by @clov3rly — 2015-10-07T22:14:27Z

Can anyone help me figure out how to do an internal redirect, using the template-wrapper?

My scenario: I have an angular app with ui-router running on ‘/category/goats-know/’. I’d like to turn on html5mode, which changes the Angular app URLS from ‘/category/goats-know/#/why-goats/’ to ‘/category/goats-know/why-goats/’. Which causes WP to 404, because such a page doesn’t really exist.

I have `base-category-goats-know.php`, and `category-goats-know.php` files

So somewhere, I want to run this code:

```
if (preg_match('/\/category\/goats-know\//', $_SERVER["REQUEST_URI"]) {
    // load category-goats-know.php inside base-category-goats-know.php
} else {
    // nothing to see here, carry on.
}
```

I’ve tried hooking into the `sage/wrap_base` filter in lib/extras.php:

```
add_filter('sage/wrap_base', __NAMESPACE__. '\sage_wrap_base_goats_know'); // Add our function to the sage/wrap_base filter
function sage_wrap_base_goats_know($templates) {
  if (preg_match('/\/category\/goats-know\//i', $_SERVER['REQUEST_URI'])) {
     array_unshift($templates, 'base-category-goats-know.php'); // Shift the template to the front of the array
  }
  return $templates; // Return our modified array with base-$cpt.php at the front of the queue
}
```

This gets me half way there, rendering the `404.php` template inside `base-category-goats-know.php`.

So I tried using WP’s filter `template_include`:

```
add_filter( 'template_include', __NAMESPACE__. '\goats_know_template', 110 );
function goats_know_template( $template ) {
  global $wp_query;
  if (preg_match('/\/category\/goats-know\//i', $_SERVER['REQUEST_URI'])) {
    if ($wp_query->is_404) {
      $wp_query->is_404 = false;
    }
    $new_template = locate_template( array( 'category-goats-know.php' ) );
    if ( '' != $new_template ) {
      return $new_template ;
    }
  }
  return $template;
}
```

This also half-works, it renders `category-goats-know.php`, but without the base template. I’ve tried it with priority of 99 and 110 with the same result.

I don’t understand enough of PHP OOP to figure out what I need from `lib/wrapper.php` alone, would sure appreciate some help from someone who knows what’s going on there…

---

## Post 2 by @austin — 2015-10-07T23:11:32Z

This should not be implemented at the WordPress level.

You are looking for a “pushstate server”. Or rather: you are trying to make a subset of your urls pushstate compatible.

> <https://stackoverflow.com/questions/13812550/configuring-nginx-for-single-page-website-with-html5-push-state-urls>

> <https://gist.github.com/rayfranco/3211654>

Instead of making the entire server pushstate just have that rule apply to a subset of paths.

That said: just use the hash. So much easier that way.

---

## Post 3 by @clov3rly — 2015-10-08T11:44:09Z

The hash _is_ a lot easier… but I need Wordpress & PHP to know the full URL so I can provide the correct meta tags/images for facebook and twitter.
