Ad

How To Remove Subdirectory In Wordpress Using Htaccess

- 1 answer

I need to change the url from:

http://example.com/*/a/any.html
http://example.com/*/b/any.html
http://example.com/*/c/any.html

to:

http://example.com/a/any.html
http://example.com/b/any.html
http://example.com/c/any.html

and if access directly to:

http://example.com/a/any.html
http://example.com/b/any.html
http://example.com/c/any.html

keep it that way

thank you all for your help in advance

Ad

Answer

If /subdir is the subdirectory you need to remove then you can try something like the following at the top of your root .htaccess file, before the existing WordPress directives:

RewriteRule ^subdir(/(a|b|c)/[\w-]+\.html)$ $1 [R=302,L]

If the subdirectory is literally any subdirectory then try the following instead:

RewriteRule ^[^/]+(/(a|b|c)/[\w-]+\.html)$ $1 [R=302,L]
Ad
source: stackoverflow.com
Ad