I need to redirect an entire subdirectory in WordPress to the homepage – is this correct?

RewriteRule ^subfolder http://www.example.com/ [R=301,L] Strictly speaking this redirects any URLs that start /subfolder, including URLs of the form /subfolderfoo and /subfolderbar which obviously don’t fall “within the subdirectory”. And this is regardless of whether “subfolder” is a physical subdirectory on the filesystem or an entirely virtual (WordPress) URL-path. (If it was a physical subdirectory then … Read more

How to remove duplicate and unnecessary part in a url using htaccess and regex?

I’m assuming any-url is literally any URL-path like foo or foo/bar/baz/something, but not nothing. Try the following: # Redirect “/customers/em/customers/any-url” to “/customers/any-url” RewriteRule ^(customers)/em/customers/(.+) /$1/$2 [R=301,L] The $1 backreference contains “customers” (saves repetition) from the RewriteRule pattern. And the $2 backreference contains the any-url part. Any query string that might be present on the request … Read more