利用域名的泛解析加上IIS配置实现windows主机的二级域名转向

写在前面:

网站有N个客户,想给每个客户都配置独立的二级域名?想让别人访问二级域名就能达到你指定的某个网站的某个目录?你用的是IIS而不是apache?你不想一个二级域名就多配置一个网站吧?好吧,看完此文你就能实现这种效果了。(此文针对windows下的IIS Rewrite展开说明,apache的同理,但没IIS复杂。)

至于如何在windows下安装Rewrite实现URL重定向可看我之前写的文章:http://www.caijierui.com/blog/?p=26

原理:

利用泛域名的解析,在服务器进行URL转向处理并转向指定的目录。

我们需要什么?

拥有域名解析权限:你能管理自己的域名,能解析二级域名(如*.caijierui.com)

有用1台服务器 或 1个能让你配置IIS的虚拟空间(甭想了)

两个网站:1个空白默认80端口的网站 + 你的网站(如caijierui.com)

如何开始?

1:首先,我们要先配置域名,如你之前的网站caijierui.com的a解析是121.198.211.250。那么你需要进行泛域名解析,我知道你在问什么是泛域名解析(泛域名解析简单点说就是做个a记录,内容为:*.caijierui.com 121.198.211.250,这样一来我随便什么二级域名,如XX.caijierui.com xxxx.caijierui.com blog.caijieurui.com w32342.caijieuri.com都指向了121.198.211.250这台服务器)。

2:先ping一下,随便输入一个二级域名,测试下是否IP为你刚设置的A记录中的IP地址?如果是,咱们再继续第三步(A记录生效一般是10分钟-12小时不等- -这个我也不知道为啥,反正你就先等个半天一天的吧)

3:在IIS中配置一个空白网站(TCP端口默认80,主机头留空的网站)。网上很多教程都是说,必须整台服务器都只有你一个网站才能实现二级域名的跳转,实际上是不需要的。只要IIS中有1个是空白的网站即可。我们需要做的是,配置这个空白网站的Rewrite,让所有指向这台服务器的域名都能重定向。

4:下载mrewrite压缩包:http://pan.baidu.com/s/1kots1,然后配置空白网站在IIS中的ISPI筛选器,至于如何配置,请看:http://www.caijierui.com/blog/?p=26这篇文章,这里就不多说了,记得要重启iis。注意:如果你的网站之前已经做过IIS Rewrite设置了,请保持和网站的Rewrite非同一个(建议直接放到空白网站的根目录下)要不然会……出现无限循环。

5:打开httpd.ini,输入以下内容即可:

[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
#进行二级域名转向,所有域名都指向让类似这样的二级域名:xxx.caijierui.com 转向 www.caijierui.com/xxx/
RewriteCond Host: (.*)\.(.*)\.((com)|(com\.cn)|(com\.hk)|(cn))
RewriteRule (.*)$ http://www\.caijierui\.com/$1/ [I,R,L]

6:至此,配置完成,已能实现二级域名转向一级域名的某个目录。

后语:

大家也能看到,实际上那样设置还没法满足太多的商业要求?对吧,例如你想截取url的id值呢?你用Rewrite去实现,很麻烦- -还不如直接在默认网站底下用ASP或PHP文件来实现跳转,具体的大家可以自由发挥。以下放出比较简单的代码用PHP实现301跳转:

<?php
$the_host = $_SERVER['HTTP_HOST'];//取得当前域名
$the_ehost= $substr($the_host,0,$strripos($the_host,".caijierui"));//截取.caijierui.com前面的二级域名
$the_val = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断地址后面部分
$the_val = strtolower($the_val);//将英文字母转成小写
if($the_val=="/index.php")//判断是不是首页
{$the_val="";//如果是首页,赋值为空}
if($the_ehost !== 'www')//如果域名不是带www的网址那么进行下面的301跳转
{
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location:http://www.caijierui.com'.$the_ehost."/".$the_val);//跳转到带www的网址
}
?>

 

原创文章,转载请注明: 转载自蔡洁锐的blog

本文链接地址: 利用域名的泛解析加上IIS配置实现windows主机的二级域名转向

利用域名的泛解析加上IIS配置实现windows主机的二级域名转向》上有346条评论

  1. wiecej pomocy

    Thank you for your entire work on this site. My aunt really likes managing investigation and it’s really easy to understand why. Most of us notice all regarding the dynamic mode you produce very useful secrets via your web blog and as well as inspire participation from some others about this subject so our favorite child is actually starting to learn a great deal. Take pleasure in the rest of the new year. You’re the one carrying out a really good job.

    [回复]

    回复
  2. zobaczysz tutaj

    Oh my goodness! an amazing article dude. Thank you However I am experiencing difficulty with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting equivalent rss downside? Anyone who is aware of kindly respond. Thnkx

    [回复]

    回复
  3. dom nad morzem

    That is the suitable weblog for anyone who desires to seek out out about this topic. You understand so much its almost exhausting to argue with you (not that I really would need…HaHa). You definitely put a new spin on a subject thats been written about for years. Nice stuff, simply great!

    [回复]

    回复
  4. An interesting story

    I wish to express some appreciation to this writer just for bailing me out of this type of matter. Right after looking out throughout the online world and meeting tricks which were not beneficial, I figured my life was gone. Being alive without the presence of answers to the difficulties you’ve resolved through your entire short post is a serious case, as well as those which might have in a wrong way affected my career if I had not encountered your web page. The knowledge and kindness in controlling the whole lot was very useful. I am not sure what I would’ve done if I hadn’t discovered such a stuff like this. It’s possible to at this time look forward to my future. Thanks so much for your specialized and results-oriented help. I will not hesitate to suggest the sites to any individual who desires counselling on this problem.

    [回复]

    回复
  5. wazny link

    Can I simply say what a aid to seek out somebody who truly knows what theyre talking about on the internet. You undoubtedly know the right way to convey a difficulty to gentle and make it important. More people need to read this and perceive this aspect of the story. I cant consider youre no more common because you definitely have the gift.

    [回复]

    回复
  6. Www.Wakawaka.Id

    We have read through some good goods in this article. Absolutely selling price bookmarking regarding revisiting. I astonish the amount energy you put to develop this type of spectacular informative web page koleksi youtube terbaik.

    [回复]

    回复
  7. Koleksi Youtube Terbaik

    Useful facts. Blessed everyone I stumbled upon your website unintentionally, with this particular astonished the key reason why this particular automobile accident did not occured previously! We saved as a favorite it koleksi youtube terbaik.

    [回复]

    回复
  8. koleksi youtube terfavorit

    Hello, Well put together publish koleksi youtube terfavorit. Likely to problem with all your internet site in net adventurer, may check this? IE ‘s still this market head and also a huge part of consumers will leave out your superb crafting because of this issue.

    [回复]

    回复
  9. My Site

    Woah the following website is extremely good i like examining your content. Continue to be within the great work! You know, plenty of people are looking around with this information, you could possibly help them greatly. Woah the following website is extremely good i like examining your content. Continue to be within the great work! You know, plenty of people are looking around with this information, you could possibly help them greatly.

    [回复]

    回复
  10. koleksi youtube terbaru

    I wouldn’t have any idea generate income appeared listed here, on the other hand imagined the following submit had been fantastic.. koleksi youtube terbaru I don’t fully grasp who seem to you might be but certainly you are going to a new well-known digg when you’re not really presently. Regards!

    [回复]

    回复
  11. koleksi youtube terfavorit

    Nice post. I’m looking at continuously this specific website and i am inspired! Extremely helpful details especially the ultimate element :) My spouse and i preserve such facts lots. I became trying to get this specific information for the number of years. Thank you so much plus enjoy.

    [回复]

    回复
  12. kumpulan youtube terbaik

    It’s proper the perfect time to produce a few options for the future and it’s time for you to feel special. I’ve check this out post and in case I could truthfully I personally prefer to suggest for you a few interesting problems or maybe tips.. kumpulan youtube terbaik You could possibly could possibly publish following posts concerning this article. I need to study even more concerns about this!

    [回复]

    回复
  13. witryna firmowa

    I’m also writing to make you be aware of what a useful discovery my friend’s princess experienced studying your site. She noticed several pieces, which included what it is like to possess a great giving mood to have a number of people quite simply comprehend specific extremely tough subject matter. You really did more than my desires. I appreciate you for providing such great, trustworthy, educational as well as easy tips on that topic to Lizeth.

    [回复]

    回复
  14. Free auto approve list 8-9-2018

    I’ve been having issues with my Windows hosting. It has set me back quite a bit while making the next list. This is the current list that I have. I should add another list in less than a week. I’ll let you all know when the next list is ready. Thank you for your patience.

    [回复]

    回复
  15. Shelton Befort gay cam

    Perfect! Interesting tips over here. It is pretty worth enough for me. Personally, if all web owners and bloggers made good content as you did, the net will be a lot more useful than ever before. I could not refrain from commenting. I have spent 1 hour looking for such infos. I’ll also share it with some friends interested in it. I’ve just bookmarked this website. Finished with the task done, I’ll visit some live gay cams. Thanks!! Greetings from Florida!

    [回复]

    回复
  16. wantclip

    Hey just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Internet explorer. I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d post to let you know. The design look great though! Hope you get the problem solved soon. Thanks

    [回复]

    回复
  17. wantclip

    I simply couldn’t leave your website prior to suggesting that I extremely enjoyed the standard info a person supply in your guests? Is gonna be again incessantly to investigate cross-check new posts

    [回复]

    回复
  18. Winford Triguro gay cam

    Mega good! Interesting information over this website. It’s pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the web will be a lot more useful than ever before. I could not resist commenting. I have spent 1 hour looking for such article. I will also share it with some friends interested in it. I’ve just bookmarked this web. Finished with the search done, I’ll enjoy some online sexy men cams. Gracias!!! Greetings from Orlando!

    [回复]

    回复
  19. Eliseo Cordoza

    This design is steller! You obviously know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job. I really loved what you had to say, and more than that, how you presented it. Too cool!

    [回复]

    回复
  20. hola

    Definitely believe that hich you said. Your favorite reason appeasred to be on the web the easiest thing to be aware of.
    I say to you, I certainly get irked while people cnsider worries that
    they just don’t know about. You managed too hit the nail upon the top as well as defined out the whole thing without havkng side-effects ,
    people could take a signal. Will probably be back to get more.
    Thanks

    Look at my webpage; hola

    [回复]

    回复
  21. paykasa

    Paykasa, 16 haneli pin kodundan oluşan, daha önce çok yaygın olarak kullanılan bir ön ödemeli kart türüne benzeyen, içerisinde euro bakiyesi olan bir ön ödemeli sanal karttır. İçerisindeki bakiyeler özel olarak üretilemediği için standart kart bakiyeleri 10, 20, 50, 100, 150, 250 tek kart bakiyesi olarak satılmaktadırlar. Tek kullanımlık bir kart olan paykasa kart, kullanılan sitede kartın bakiyesini girmenize gerek kalmadan sadece 16 haneli tek kullanımlık koduyla işlem yapmanıza olanak sağlamaktadır.

    [回复]

    回复
  22. Lucio Kanode gay cam

    Cool! Interesting informations over here. It’s pretty worth enough for me. In my view, if all website owners and bloggers made good content as you did, the web will be a lot more useful than ever before.| I could not refrain from commenting. I have spent 1 hour searching for such tips. I will also share it with some friends interested in it. I have just bookmarked this website. Right now with the search done, I going to visit some online homo cams. Gracias!!!Greetings from San Francisco!

    [回复]

    回复
  23. Davis Assante gay cam

    Good one! Interesting article over this website. It is pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the net will be a lot more useful than ever before.| I couldn’t refrain from commenting. I have spent 2 hours looking for such informations. I will also share it with a couple of friends interested in it. I have just bookmarked this website. Now with the work done, I’ll enjoy some live gay webcams. Merci!!Greetings from San Francisco!

    [回复]

    回复
  24. odwiedz

    I wish to show thanks to the writer for rescuing me from such a issue. After surfing through the the web and finding ways which are not powerful, I believed my entire life was done. Being alive devoid of the strategies to the issues you’ve fixed all through your main report is a critical case, and those that would have in a negative way damaged my career if I had not come across your web page. Your good ability and kindness in handling all things was excellent. I am not sure what I would have done if I hadn’t encountered such a stuff like this. I’m able to at this moment look ahead to my future. Thanks for your time very much for the expert and results-oriented help. I won’t be reluctant to propose your web site to any person who needs guidance about this subject.

    [回复]

    回复
  25. Moshe Grandbois gay cam

    Super! Interesting info over this website. It’s pretty worth enough for me. Personally, if all web owners and bloggers made good content as you did, the net will be a lot more useful than ever before.| I could not refrain from commenting. I have spent some hours trying to find such informations. I will also share it with a couple of friends interested in it. I’ve just bookmarked this website. Now with the job done, I will find some model gay webcams. Gracias!!!Greetings from Orlando!

    [回复]

    回复
  26. Lesbian Stepsisters

    There’s nothing hotter in this entire world than seeing two girls make sweet love. Seeing a girl face deep in pussy is a dream come true. Dreams have a way of turning into reality at https://t.frtyt.com/ekuezzm5kw?aff_id=29696&offer_id=5407&nopop=1 This site is dedicated to stepsisters who love to lick and finger each other. You always knew stepsisters did this sort of thing with each other. You just never seen it with your own eyes until now!

    [回复]

    回复
  27. Get laid today

    Are you looking to get laid today? As in right this fucking minute? If so, then you need to check out https://t.hrtye.com/ze97vsfi2o?aff_id=29696&offer_id=5614&nopop=1 This is the one site where you can get some action the same day you join. Don’t even fool around with Facebook and those other so called dating sites. You’re never going to get laid at any of those places. There’s all kinds of pussy just waiting for you to pound it silly here. Don’t forget to buy a box of condoms while you’re out today. You’re going to need them!

    [回复]

    回复
  28. Ganar Dinero

    Hey! I know this is kinda off topic but I’d figured I’d ask.
    Would you bee interested in trading links or maybe guest writing a blog post or vice-versa?
    My blog disccusses a llot of the same topics as yours aand
    I think we coujld greatly benefit from each other.
    If you happen to be interested feel free to end
    me an e-mail. I loook forward to hearing from you!

    Terrific blog by the way!

    Here is my web-site … Ganar Dinero

    [回复]

    回复
  29. Brande Demarzio

    Greetings from Los angeles! I’m bored at work so I decided to browse your website on my iphone during lunch break. I enjoy the information you present here and can’t wait to take a look when I get home. I’m surprised at how fast your blog loaded on my phone .. I’m not even using WIFI, just 3G .. Anyways, very good blog!

    [回复]

    回复
  30. Vassil Bojkov

    Hi aree using WordPress forr your site platform?
    I’m new to the blog world but I’m trying to gett tarted and create my own. Do you require anny html coding knowledge to
    make your own blog? Any help would be greatly appreciated!

    My blog … Vassil Bojkov

    [回复]

    回复
  31. Quincy Pouliotte gay cam

    Good! Interesting tips over this website. It is pretty worth enough for me. In my view, if all webmasters and bloggers made good content as you did, the net will be a lot more useful than ever before.| I couldn’t resist commenting. I have spent some time looking for such informations. I will also share it with some friends interested in it. I have just bookmarked this web. Right now with the task done, I’ll find some live gay cams. Thanks!!Greetings from Miami!

    [回复]

    回复
  32. sa

    I’ve just added a fresh new list. This is by far the biggest list to date. I hope you all are having a great week. Take care and happy link building.

    [回复]

    回复
  33. Best online dating

    Are you sick and tired of being lonely? Why should you not have someone special in your life? Everyone deserves to find love. You can find that and a whole lot more at https://t.irtyc.com/avekqggwlc?aff_id=29696&offer_id=3785&bo=2753,2754,2755,2756 This is one of those sites where it’s super easy to hook up. You’ll meet all kinds of girls. Don’t sit on the couch and hang out online all night. Hook up with a chick and have yourself a little fun. Every guy deserves to have a gal in his life. What are you waiting on?! Connect with a cutie today and put a smile all over your face.

    [回复]

    回复
  34. Pingback引用通告: Booker Kosters

  35. pielegnacja oparzen

    I wanted to post you the very small observation just to say thanks a lot again relating to the nice secrets you have shown here. This is really shockingly open-handed with you to present publicly what numerous people might have made available as an e-book to earn some money for their own end, notably now that you could have tried it in the event you considered necessary. Those good tips also worked like a good way to comprehend other individuals have the same passion similar to my own to grasp way more pertaining to this problem. I’m sure there are several more pleasurable sessions up front for individuals who looked at your site.

    [回复]

    回复
  36. Sexy fat girls

    Are you the type of guy who likes to look at fat girls naked? If so, then https://t.frtyh.com/755v8haio0?aff_id=29696&offer_id=5331&bo=2753,2754,2755,2756 is the site you’ve been searching for. It’s full of nothing but sexy fat women. These big beautiful women are exactly what your eyeballs have been begging to see. Don’t be surprised if you pop a boner while looking at these hefty honeys. They’re full of curves and are exactly what your penis likes.

    [回复]

    回复
  37. creditos con asnef

    Undeniably consider that which you said. Your favourite justification appeared to be at the internet the simplest thing to be mindful of.
    I say to you, I certainly get annoyed whilst folks consider
    concerns that they just don’t know about. You managed to hit the nail upon the top as neatly as defined out
    the whole thing without having side effect , other people can take a signal.
    Will probably be back to get more. Thank you

    creditos con asnef

    [回复]

    回复
  38. instagram download

    My spouse and I totally like your blog and find a lot of your articles to be precisely what I am interested in. Do you offer people to write material for you? I wouldn’t mind composing an article relating to luck patcher apk or on some of the things you write about on this site. Awesome information site!

    [回复]

    回复
  39. Wilburn Ottino

    I am not sure where you are getting your information, but good topic. I needs to spend some time learning more or understanding more. Thanks for excellent info I was looking for this info for my mission.

    [回复]

    回复

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>