Andre Guerra
Andre Guerra

Reputation: 21

How do I redirect any url/page in a sub folder to another URL?

I have a custom post type in Wordpress the following slug:

domain.com/folder/page-1

I want to redirect all /folder/ links/URLS to another URL.

For example:

  1. domain.com/folder/page-1
  2. domain.com/folder/page-2
  3. domain.com/folder/page-3

All redirect to domain.com/some-page

Upvotes: 1

Views: 1199

Answers (3)

Aryan Aryan
Aryan Aryan

Reputation: 38

If you have many URLs to redirects, its better to use plugins, suggest plugin Simple 301 Redirects

Another methods is use wordpress function wp_redirect();

add_action('template_redirect', 'redirect_page_another_page');

if(!function_exists('redirect_page_another_page')){

   function redirect_page_another_page(){

   $queried_post_type = get_query_var('post_type');
   <!-- replace custom_post_type_name with you custom post type name -->
  if ( is_single() && 'custom_post_type_name' ==  $queried_post_type ) {
  $redirect_url = site_url().'/folder/some-page/';
  wp_redirect( $redirect_url );
  exit;
  }
 }
}

Upvotes: 0

Amit Verma
Amit Verma

Reputation: 41229

You can use RedirectMatch directive for this :

RedirectMatch ^/folder/.+$ http://example.com/page

Upvotes: 0

Martin Carstens
Martin Carstens

Reputation: 736

How about:

RewriteEngine on
RewriteRule ^domain.com/folder/(.*)$ domain.com/some-page [R=301,L]

Upvotes: 1

Related Questions