我们有2个DNS条目为我们的公司网站;我们的旧域名仍然有效,我们的新域名在我们所有的广告中使用,但许多用户有我们的旧网站书签。
我们为需要用户输入个人信息的4个页面安装了SSL证书。我有一个http到https的重定向,如下所示:
<script> if(location.protocol.indexOf("https") === -1) { location.href = location.href.replace("http", "https"); }</script>除非有人从我们的旧域进入页面,然后URL中的域名与证书不匹配,用户就会从他们的浏览器得到一个令人讨厌的警告。
我复制了下面的代码,我认为如果他们使用以前的域名来到这个页面,我会重定向,但它似乎不起作用。
<script>if (document.referrer == 'olddomain.co.jp' || document.referrer == 'www.olddomain.co.jp') == 1)
{ top.location="https://newdomain.com/english/engform.aspx";}
但它不会重定向;它仍然会给我警告。有什么建议吗?
发布于 2014-03-27 16:05:03
然后,您只需检查它是否是旧域名,并使用您在问题中描述的相同方法将它们发送到新域名
if (location.href.indexOf("oldsite.domain") > -1) location.href = location.href.replace("oldsite.domain", "newsite.domain");发布于 2021-11-14 11:09:33
你需要获得的证书,包括你的旧域和新域。如果没有旧域的证书,浏览器会在 your JavaScript运行之前显示一个安全警告。
执行此操作的典型方法是获取一个主题备用名称(SAN)证书,该证书同时涵盖您的旧域和新域。然后,您可以对这两个域使用相同的证书、服务器配置和文档根目录,并使用.htaccess (首选)或JavaScript从一个域重定向到另一个域。
发布于 2021-11-13 21:08:03
function RedirectUrl() {
var expression = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/
var regex = new RegExp(expression);
var current_url = window.location.href;
var redirect_url = "/news"; /* where news is like news.html same news-inspiration is a news-inspiration.html like www.abc.com/news-inspiration */
if (current_url.indexOf('/news-inspiration') > -1) {
if (!current_url.match(redirect_url) && current_url.match(regex)) {
window.location.replace(redirect_url);
}
}}
在使它成为函数之后,在任何javascript事件期间调用它。//调用函数
RedirectUrl();https://stackoverflow.com/questions/22681422
复制相似问题