How to redirect all pages under WP directory to go back to the homepage

We had a sloppy web designer who created a new design, they made a /development page on our website by creating a new wordpress install and failed to make it noindex, nofollow so all of our main page is being duplicated in Google under /development.

So I want to redirect all pages found under this directory straight back to the homepage (not strip out only /development)

Read More

So this means /development goes to domain.com
and
/development/howtofindhelp.html goes to domain.com (homepage) without the extension.

I tried using this and it doesnt seem to work at all, it basically just adds the trailing slash on the end:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^development(.*)$ https://domain.com/$1 [L,R=301]

Related posts

Leave a Reply

2 comments

  1. you can add below code on functions.php on top .

    $currernt_url=$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
        if($currernt_url!='your domain'){
         wp_redirect( home_url() );
         exit; 
        }
    

    you can add any url in “your domain”section then it compare with this url except “your domain ” it will redirect to home page. you can also use multiple “url” using or Or condition in if condition

  2. For those interested, since I couldnt get the code to work for the header.php I tried something else.

    Just edit the wp-config.php and I took off the /development so its just the main homepage. By default when you try to load the page it will jsut say not found. But you can install the 404 to 301 plugin which will redirect all 404 pages.

    Since this /development is on its own wordpress install I am fine with it redirecting automatically since the main wordpress install wont have this plugin.