RewriteRule ^$.-detail https://www.example.com/$1-detail [R=301,L]
There are few issues with the regex:
- The
$
(end-of-string anchor) is in the wrong place. This should be at the end of the regex (you want to match .-detail
at the end of the URL-path, ie. \.-detail$
).
- There is no capturing subpattern, so the
$1
backreference is always going to be empty.
- The literal dot should be backslash-escaped, otherwise this matches any character and would result in a redirect-loop (if there was a capturing subpattern as mentioned above) - since it would also match the redirected URL, reducing it by 1 character at a time until there's nothing left of the URL!
The RewriteRule
pattern (first argument) should be more like this:
(.+)\.-detail$
The ^
(start-of-string anchor) is not required since regex is greedy by default and the dot matches "everything". (Although you could include it if it makes it easier for you to read.)
The $1
backreference then contains the part of the URL-path matched by the parenthesized subpattern (.+)
.
You could capture both parts, before and after the dot, to save repeating the literal string in the substitution. For example:
RewriteRule (.+)\.(-detail)$ https://www.example.com/$1$2 [R=301,L]
The $2
backreference simply contains the string -detail
, as captured from the second capturing group in the RewriteRule
pattern.