Why does this regular expression skip site.com without a slash at the end?

 if(!preg_match('|^(http(s)?://)?(www.)?site.com/*|i', $_POST['site'])) { 

I need to check for a slash after the domain name

  • You put /* at the end. those. sign / may not be there. Change to /+ or just to / - Yuri

2 answers 2

Put in place of * - +

'^(http(s)?://)?(www.)?site.com/+'

    It would be more correct to |^(http(s)?://)?(www\.)?site\.com/$|i , which means - after a mandatory / nothing should not go.

    Just do not forget to put a backslash \ before the dots, otherwise http://site-com will also be tested.