I’m using this code to redirect visitors who are coming from another site (clicking on my ad on that site) to a page in my site where I can track them:
The problem is that, by this code I can only redirect those who are coming from example.com/shop, but I need to redirect visitors coming from any sub directory or subdomain from example.com, not only a specific url in example.com
Good point, I’ve never got my head around regular expressions. So the parse_url will split the ‘example.com’ from the ‘/shop’ in the first example so it’s always at the end of the comparison string?
Yes. Using PHP_URL_HOST it returns the host from any URL, which in the first example will indeed be example.com.
The regular expression says that the string must end in “example.com”, so example.com and all subdomains will match.
You can use parse_url to get more than the host. Check it out in the manual: [fphp]parse_url[/fphp]