If you want to redirect /shop/contact-us
with a number of optional trailing slashes to http://www.example.com/contact-us
, then the Redirect
directive is not very appropriate. Use RedirectMatch
directive instead:
RedirectMatch 301 "^/shop/(contact\-us)/?" http://www.example.com/$1/
where
-
^
is an anchor meaning "beginning of the line";
-
/?
matches zero or one slash character;
-
(contact\-us)
is a capturing group (referenced by $1
)
Note, the regular expression matches only the prefix, since only the ^
anchor is used. You can use the $
(end of the line) anchor in order to make the expression stricter, e.g.:
RedirectMatch 301 "^/shop/(contact\-us)/*$" http://www.example.com/$1/
where /*
means zero or more slashes.