问题
Brief Idea: I am building script for protecting my webdesign work by locking them on Single domain. If website is uploaded on different domain, It will redirect to my website. Means it won't allow to load actual website from different domain except I specify them.
My Working Script:
-- DECODED SCRIPT --
[]['constructor']['constructor'](self['unescape']('if(~location.protocol.indexOf('http:')&&~location.host.indexOf('isupportu.in')){}else(location.href='http://iamwebdeveloper.in')'))()
Here on above code, I am allowing my work to load on "www.abc.com" with http protocol only. However it won't work if we load website without www i.e. "abc.com".
www.abc.com --> Website load
abc.com --> www.iamwebdeveloper.in
xyz.com --> www.iamwebdeveloper.in
www.xyz.com --> www.iamwebdeveloper.in
I decided to use .htaccess
/ web.config
file to force redirect domain without www. request to www.abc.com [which is working very well]
But now I want to upgrade this script and I need your help:
- Don't want dependency on .htaccess / web.config file for redirecting non www. request.
- www. and non www request should accept, but no subdomain allow. For e.g. subdomain.abc.com is not allowed.
- I want to add multiple domains in script for big clients who has multiple domain for their single website as Addon domain. I want to add more domain in above script.
Can someone help me to validate this script for my above logic ?
[]["constructor"]["constructor"]
(
self["unescape"]
("<!-- I WILL USE THIS CODE AFTER CONVERTING TO ESCAPE TEXT AND IGNORE THIS COMMENT -->
if (location.protocol.indexOf("http:") && ( (location.host.indexOf("isupportu.in")) || (location.host.indexOf("paytronicindia.com")) || (location.host.indexOf("paytronicworldwide.com")) || (location.host.indexOf("paytronicnetwork.com")) )
){}else(location.href='http://iamwebdeveloper.in')
")
)
()
回答1:
It looks like your real question is something like "How can I check in JavaScript whether the hostname of the current page is one of a specific list of domains, with or without a www.
prefix?"
There are many ways to do that, but one fairly simple one would be to match a regexp against location.hostname:
var re = /^(www\.)?((site1|site2|site3)\.in|(site4|site5)\.com)$/;
if ( !re.test( location.hostname ) ) {
location.href = 'http://yourwebsite.in';
}
Obfuscating that is left as an exercise.
来源:https://stackoverflow.com/questions/15965035/redirect-website-if-its-not-specified-domain-in-script-protection-using-javasc