重定向网站(如果未在脚本中指定域)-使用Javascript进行保护 [英] Redirect Website if its not specified domain in script - Protection using Javascript

查看:107
本文介绍了重定向网站(如果未在脚本中指定域)-使用Javascript进行保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简要说明::我正在构建脚本,以通过将其锁定在单个域上来保护我的网页设计作品.如果网站是在其他域上载的,它将重定向到我的网站.意味着除非我指定它们,否则不允许从其他域加载实际的网站.

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.

我的工作脚本:

-- DECODED SCRIPT --

[]['constructor']['constructor'](self['unescape']('if(~location.protocol.indexOf('http:')&&~location.host.indexOf('isupportu.in')){}else(location.href='http://iamwebdeveloper.in')'))()

在上面的代码中,我允许我的工作仅使用http协议加载到"www.abc.com"上. 但是,如果我们在没有www的情况下加载网站,即"abc.com",则将无法正常工作.

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

我决定使用.htaccess/web.config文件来强制没有www的重定向域.向www.abc.com的请求[效果很好]

I decided to use .htaccess / web.config file to force redirect domain without www. request to www.abc.com [which is working very well]

但是现在我想升级此脚本,并且需要您的帮助:

  • 不想依赖.htaccess/web.config文件来重定向非www.请求.
  • www.并且非www请求应接受,但不允许子域访问.例如不允许subdomain.abc.com.
  • 我想为脚本中的多个客户添加多个域,这些客户的单个网站具有多个域作为Addon域.我想在上述脚本中添加更多域.

有人可以帮我根据我的上述逻辑验证此脚本吗?

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')
    ")
)
()

推荐答案

看起来您的 real 问题类似于"如何在JavaScript中检查当前页面的主机名是特定域列表之一,带或不带www.前缀?"

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?"

有很多方法可以做到这一点,但是一个相当简单的方法就是匹配 regexp 针对 location.hostname :

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';
}

混淆作为练习.

这篇关于重定向网站(如果未在脚本中指定域)-使用Javascript进行保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆