I have either of the following URLs: http://www.scenemovie.org or http://subdomain.scenemovie.org
I want to keep "scenemovie.org" and remove "http://www.". How can this be accomplished with jQuery? Thanks!
I have either of the following URLs: http://www.scenemovie.org or http://subdomain.scenemovie.org
I want to keep "scenemovie.org" and remove "http://www.". How can this be accomplished with jQuery? Thanks!
If there is a sub-subdomain, then this regex return only domain:
url = 'http://a.sub.subdomain.exemple.com';
domain = url.match(/[^\.]*\.[^.]*$/)[0];
url = 'http://www.scenemovie.org';
domain_and_tld = url.replace(/http:\/\/.+?\./, '')
How to do that with jQuery?
In the general case where you may not know what the required domain is, you can't.
There's no specification for what constitutes a "subdomain" as you've used the term in the DNS. In effect what you're looking for is an administrative boundary within the DNS, but there's no deterministic way to tell where those administrative boundaries are.
For example, I happen to know the owner of www.me.uk
. That is a correctly registered domain name in its own right, even though it looks like a "subdomain".
The closest you can get (although even that is flawed) is to compare the domain against the "Public Suffix List", which is an attempt to create a definitive list (it isn't) of which domains are "registerable domains".
Try htaccess:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>