How to redirect only when exact url matches?

后端 未结 2 2037
名媛妹妹
名媛妹妹 2021-01-31 03:21

I\'m trying to redirect with apache .htaccess. I have the following codes

redirectMatch 301 /user http://clients.mydomain.com

it works pretty w

2条回答
  •  情歌与酒
    2021-01-31 03:23

    Simple add a ^ to beginning and a $ to the end

    ^ tells tells the regex to match the beginning of the url

    $ tells tells the regex to match the end of the url

    redirectMatch 301 ^/user$ http://clients.mydomain.com
    

    So now your rule will only match /user and not /some/user or /user/name or /some/user/name


    NOTE: If you want to match /user/ and /user then use ^/user/?$

    ? says to match the previous character/group zero to one times

提交回复
热议问题