Get domain name (not subdomain) in php

Well you can use parse_url to get the host: $info = parse_url($url); $host = $info[‘host’]; Then, you can do some fancy stuff to get only the TLD and the Host $host_names = explode(“.”, $host); $bottom_host_name = $host_names[count($host_names)-2] . “.” . $host_names[count($host_names)-1]; Not very elegant, but should work. If you want an explanation, here it goes: … Read more

How to validate domain name in PHP?

<?php function is_valid_domain_name($domain_name) { return (preg_match(“/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i”, $domain_name) //valid chars check && preg_match(“/^.{1,253}$/”, $domain_name) //overall length check && preg_match(“/^[^\.]{1,63}(\.[^\.]{1,63})*$/”, $domain_name) ); //length of each label } ?> Test cases: is_valid_domain_name? [a] Y is_valid_domain_name? [0] Y is_valid_domain_name? [a.b] Y is_valid_domain_name? [localhost] Y is_valid_domain_name? [google.com] Y is_valid_domain_name? [news.google.co.uk] Y is_valid_domain_name? [xn--fsqu00a.xn--0zwm56d] Y is_valid_domain_name? [goo gle.com] N is_valid_domain_name? [google..com] … Read more

Nginx 403 error: directory index of [folder] is forbidden

If you have directory indexing off, and is having this problem, it’s probably because the try_files you are using has a directory option: location / { try_files $uri $uri/ /index.html index.php; } ^ that is the issue Remove it and it should work: location / { try_files $uri /index.html index.php; } Why this happens TL;DR: … Read more