如果网站名称与我的字词不匹配,我想在我的HTML / PHP中添加一个重定向脚本。我尝试使用此代码,但它不起作用。
WITH REGEX
if (window.location.hostname !== 'myword.org'){
window.top.location.href = 'http://redirecttomysite.org';
}
var website = window.location.hostname;
var internalLinkRegex = new RegExp('^((((http:\\/\\/|https:\\/\\/)(www\\.)?)?'
+ website
+ ')|(localhost:\\d{4})|(\\/.*))(\\/.*)?$', '');
没有REGEX
if (website !== 'myword.org'){
window.top.location.href = 'http://redirecttomysite.org/forum';
}
答案 0 :(得分:1)
试
if (website.indexOf('myword.org') == -1){
window.top.location.href = 'http://redirecttomysite.org/forum';
}
答案 1 :(得分:0)
简单如下
[NotifyPropertyChanged]
public class Test {
public int PropVal { get; set; }
public List<string> PropCollection { get; set; } //Should this be ObservableCollection
//or AdvisableCollection?
}
与HTTP重定向类似的行为
if (!(/stackoverflow\.com/i.test(location.hostname))){
...
与点击链接相似的行为
window.location.replace("http://stackoverflow.com");
答案 2 :(得分:0)
if(window.location.href.indexOf("myword.org") == -1) {
window.location = 'http://redirecttomysite.org';
}