Home > Enterprise >  Tricky htaccess redirect using a wildcard for subfolder
Tricky htaccess redirect using a wildcard for subfolder

Time:07-07

I have a client request to rewrite the following, where "anything" can be any named directory:

https://clientdomain.com/anything/final-destination

to:

 https://clientdomain.com/final-destination

I know I can identify "anything" with the following regex:

(?<=clientdomain.com\/)(.*)(?=final-destination)

...but how to incorporate that into a working rule eludes me

CodePudding user response:

You may use this rule without any lookahead:

RewriteEngine On

RewriteRule ^[^/] /(final-destination/?)$ /$1 [L,NC,R=301]

Here [^/] matches 1 or more of any character that is not /.

  • Related