Categories
Tech

绑定子域名

国内很多主机都不支持绑定域名到子目录上,其实用一段javascript就能实现。

<script type=”text/javascript”>
var str = location.hostname
var domain1 = “domain1.com”
var domain2 = “domain2.com”
if (str.match(domain1) == domain1)
window.location = “new URL#1”
else if (str.match(domain2) == domain2)
window.location = “new URL#2”
</script>

对于Wordpress系统,这段代码最好扔到所用主题的header.php里<body>段的开头,如果直接放在index.php里可能会把WP的RSS弄坏掉,出现”XML declaration allowed only at the start of the document”(Safari下)之类的错误(我到今天才发现RSS已经挂掉一周了……)。

ps. 可以到Feed Validator验证RSS是否有效。

Leave a Reply

Your email address will not be published. Required fields are marked *