I am trying to create a regex for 301s that will help me identify the url: site.com/abc/
and redirect to site.com/xyz/
. I've tried regex as ^abc/?
and it works fine but the problem is even urls like site.com/123/sdas/abc/213
are getting caught. How can I ensure only /abc
gets matched with the full string url?
To expand the regex to match a complete line, add ‹ . * › at both ends. The dot-asterisk sequences match zero or more characters within the current line.
A regular expression (regex) defines a search pattern for strings. The search pattern can be anything from a simple character, a fixed string or a complex expression containing special characters describing the pattern.
The "m" modifier specifies a multiline match. It only affects the behavior of start ^ and end $. ^ specifies a match at the start of a string.
Use the end of line anchor $
:
^abc/$
This ensures that the exact string abc/
will be matched.
$ matches end of string:
^abc/?$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With