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

Point all URLs to homepage but maintain URL

Add this code to the functions.php file of your (child) theme or as a plugin- add_action( ‘init’, ‘wpse_393237_add_any_endpoint’ ); function wpse_393237_add_any_endpoint() { add_rewrite_endpoint( ‘.*’, EP_ALL ); } Please note, you may need to flush the rewrite rules if you see a 404 error. (simply saving the permalink does the trick) Ref: https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/

Change htaccess to redirect to index.php in subfolder

Try something like the following at the top of the root .htaccess file, before the existing WordPress directives (before the # BEGIN WordPress comment marker): RewriteCond $2 !^(index\.php)?$ RewriteRule ^(subfolder)/(.+) /$1/index.php?path=$2 [L] The RewriteCond directive is to ensure that it doesn’t try to rewrite requests for index.php itself (or the directory). A request for /subfolder/ … Read more