3

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

mayersdesign
  • 5,062
  • 4
  • 35
  • 47

1 Answers1

1

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 /.

anubhava
  • 761,203
  • 64
  • 569
  • 643