裸體網域自動轉 www 很重要

紅寶鐵軌客
Join to follow...
Follow/Unfollow Writer: 紅寶鐵軌客
By following, you’ll receive notifications when this author publishes new articles.
Don't wait! Sign up to follow this writer.
WriterShelf is a privacy-oriented writing platform. Unleash the power of your voice. It's free!
Sign up. Join WriterShelf now! Already a member. Login to WriterShelf.
寫程式中、折磨中、享受中 ......
1.13K   0  
·
2019/01/03
·
4 mins read


Woman Wearing Gold-colored Framed Eyeglasses

一寫到「裸體」就有點流汗,搞色情啊。

不是不是,是我真的不知道要怎麼說這的,就直接翻譯了,英文就叫「naked domain」,這裸體網域就是大家花錢買的網域名稱啦,像是 google.com,yahoo.com 或是我現在用的 scrivinor.com,那為什麼要叫裸體呢?很簡單啦,就是要跟子網域有點區分,沒加 www 或是其他子網域的,就叫裸體網域。

我想大家應該都知道,www.lovelove.com 跟 lovelove.com 是不一樣的網域,但是大家可能都忘了,在網路上,還有很大的一群使用者,他們習慣不打 www,所以,如果沒有設定好,其實,用戶使用的就會是不一樣的網域。

很多人網管人,就直接在 A record註一 中,設兩個,都指到同一個 ip,這其實也是對的,但是,這很有可能會為程式開發帶來一些討厭的挑戰,最主要的挑戰就是 CORS,CORS 是跨來源資源共用(Cross-Origin Resource Sharing),要知道更多 CORS ,這篇值得一讀: 筆記 - 什麼是CORS?。 但是,這樣做,必須要了解的是,這就是兩個不同的網域,不是一個。

人生本來就是苦短,何必一次搞兩個,多個香爐多個鬼絕對是名言,相信我,搞兩個網域,很快就會碰到很多 CORS 問題,特別是 JavaScript,流量分析也會有問題,所以,最好的方式就是只專心一個,就像,愛情?!

我的建議是自動轉 www,也就是以 www 為本,把裸體網域自動轉到 www 子網域,也就是說,如果用戶輸入的網址是 lovelove.com,那就直接給他 forward 轉址到 www.lovelove.com,這樣,就一定只有一個了,這樣就可以專心了。

只是啊只是,很快就會發現,很不好搞,有人說把 CNAME 設成 www 裸體網域就好,有聽說 GoDaddy 可以用遮罩等,還有聽說有些賣網址的乾脆直接有一個選項,自動 naked domain 轉址,只是不幸的我,是用 google domain,所以,要走直路,還好,也不難!也就是兩步驟:

  1. 把 www. 設為主網站:將 www 加入 A record 中,並設定 ip,ex: www / A / 1h / 110.12x.xx.xxx,這樣,當使用者網址打入 www.lovelove.com 時,就可以連到你的伺服器了,只是,打 lovelove.com 不會動了,別擔心,看下面。
  2. 轉裸體網域到 www:設定轉址,在 google domain 中,就在 Synthetic records 中增加一筆 lovelove.com  http://www.lovelove.com,Temporary redirect (302), Forward path, Enable SSL

你可能會看到 SSL 沒有設定的警告,但是如果你的 SSL 確定有設好,就別管它,就這樣,裸體網域自動轉 www 就好了,我想這種設定應該是很標準的,所以除了 google domain 外,因該都可以用,希望對大家有幫助了。

註一:什麼是 A record?

A 就是地址啦,所以,就是當你買了網名後,你要這個網名指到那個 ip 啦,裡面有幾個設定值:

  1. Name: 使用 @ 就代表是指裸體網域,輸入“www“,就是 www.xxx.xxx,email 或是其他自網域都可以用這個來指定。
  2. IP: 就是你要指到那個 ip
  3. TTL: 就是英文 Time To Live 的縮寫,啟動時間,一般翻譯為存留時間,用來定義 DNS 記錄的後續變更生效前的秒數,很昏,基本上就是說您下次更改記錄時,您的變更會在多久後生效啦,用浮動 ip 就設短一點,五分鐘(300)吧,固定 ip 的,設個一天(86400)也 ok。

紅寶鐵軌客

聽說按個關注,就可以收到我的新文章通知了⋯⋯


WriterShelf™ is a unique multiple pen name blogging and forum platform. Protect relationships and your privacy. Take your writing in new directions. ** Join WriterShelf**
WriterShelf™ is an open writing platform. The views, information and opinions in this article are those of the author.


Article info

Categories:
Tags:
Date:
Published: 2019/01/03 - Updated: 2019/01/04
Total: 930 words


Share this article:
About the Author

很久以前就是個「寫程式的」,其實,什麼程式都不熟⋯⋯
就,這會一點點,那會一點點⋯⋯




Join the discussion now!
Don't wait! Sign up to join the discussion.
WriterShelf is a privacy-oriented writing platform. Unleash the power of your voice. It's free!
Sign up. Join WriterShelf now! Already a member. Login to WriterShelf.