Search code examples
wordpress.htaccesshttp-redirecthttp-status-code-301

htaccess redirect folders with specific word to their own parent folder


New site is live and the old site made use of a bunch of useless "feeds".

Looking for an .httaccess 301 redirect command to redirect anything with "feed" in it to its parent folder. There are thousands of them, so looking for a way to do it in one fell swoop.

Here are examples of the "folders" (which are really WordPress pages):

http://example.com/listing/listing-name/feed/

http://example.com/listing/listing-name2/feed/

Where "listing" always remains the same, but "listing-name" and "listing-name2" represents items that vary.

I would like them to be redirected to their parent "folder", like this:

http://example.com/listing/listing-name/

http://example.com/listing/listing-name2/

Any help would be greatly appreciated.

Thank you!


Solution

  • You can use this redirect rule as your top rule:

    RewriteEngine On
    
    RewriteRule ^(.+/)feed/?$ /$1 [L,NC,NE,R=301]
    
    # more rules below this