RegEx matches full string

I am trying to create a regular expression for 301 that will help me identify the URL: site.com/abc/ and redirect to site.com/xyz/ . I tried regex like ^abc/? and it works great, but the problem is that even URLs like site.com/123/sdas/abc/213 get in. How can I guarantee that only /abc will be matched with the full string URL?

+6
source share
3 answers

Use $ end of line binding:

 ^abc/$ 

This ensures that the exact string abc/ matches.

+12
source

$ matches the end of a line:

 ^abc/?$ 
+2
source

Write your rule as follows:

 RewriteRule ^abc/?$ /xyz [L,NC] 
0
source

Source: https://habr.com/ru/post/888075/


All Articles