How to remove specific subdirectories in .htaccess file

Even after extensive research I was unable to resolve following redirection. I tried tons of examples, but with no luck.

From this URL:
http://www.example.com/store/product/name

Read More

I would like to get:
http://www.example.com/name

Problem is that the only known string is “store”. Other strings “product” and “name” could contain letters, numbers and “-” or “_” characters.

I am testing it on live website and also on this tester: htaccess.madewithlove.be

One of the examples I used:

RewriteEngine On
RewriteBase /
RewriteRule ^store/([^/]+)/([^/]+) $2 [L,R=301]

This seems to work on above tester website, but not in real environment. I think there is something wrong with the regexp and second parameter is not properly returned or I am missing something else.

I should also mention that the website runs on WordPress and in .htaccess file there is also following section created automatically by WordPress:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Thanks for your help!

Related posts

Leave a Reply

1 comment

  1. Have your rule like this i.e. redirect before internal WP rule:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^store/([^/]+)/([^/]+) $2 [L,R=301]
    
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress