title: Wordpress - Redirect a page if the page doesn't exist
body: <p>I am trying to redirect a user from; <code>website.com/properties/property-title</code> to <code>website.com/archive_properties/property-title</code> if the URL doesn't exist.</p>
  
  <p>The below code is working if the URL that it is redirecting to is actually a page, if the page doesn't exist then I get an error; redirected you too many times and the URL is changed to <code>/archive_archive_archive_archive_archive_archive_archive_archive_archive_archive_archive_properties/property-title</code></p>
  
  <p>Is there a way I can just display the normal 404 page if the page doesn't exist?</p>
  
  <pre><code>add_filter( '404_template', function( $template ) {
  
      $request = filter_input( INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING );
  
      if ( ! $request ) {
          return $template;
      }
      $regex = [
          '/properties/'    =&gt; 'archive_properties/$1',
      ];
  
      foreach( $regex as $pattern =&gt; $replacement ) {
          if ( ! preg_match( $pattern, $request ) ) {
              continue;
          }
          $url = preg_replace( $pattern, $replacement, $request );
  
          wp_redirect( $url, 301 );
          exit;
      }
  
      // not our business, let WP do the rest.
      return $template;
  
  }, -4000 ); // hook in quite early
  </code></pre>