Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(): Failed opening '/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24
2013 年 9 月 – unethost無限空間虛擬主機 技術分享部落格

如何將「主域名」指向「子資料夾」

客戶常常有一種情況,把論壇或是CMS的主程式,灌在public_html這個資料夾下的某個子資料夾,例如bbs,之後又提交服務單給身為主機商的我,希望他的網址,可以是 http://example.com/index.php 而不是 http://example.com/bbs/index.php 簡單的說,就是希望可以做apache mod_rewrite把子資料夾(subdirectory)的路徑去掉。

要做這件事,步驟如下:
(1) 在public_html下,新增一個.htaccess
(2) 在.htaccess檔案,複製貼上,下方的內容。並且替換example.com為客戶的主域名,替換subdirectory為客戶的子資料夾,替換index.html為子資料夾裡的索引檔。

# UnetHost.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change ‘subdirectory’ to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don’t change these line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change ‘subdirectory’ to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.com to be your main domain again.
# Change ‘subdirectory’ to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.html [L]

什麼是Punycode?

最近收到客戶的請求,要我去幫客戶註冊一個中文域名。我想,這是什麼東西啊?客戶說,他要註冊的域名是像這樣子「印表機.com」這種的。後來,我研究了一下,才知道有一個專有名詞,叫做Punycode。在註冊中文域名之前,要先轉碼成Punycode,才能註冊。

查了一下網路上的資料,「什麼是Punycode?」

一般的域名在IIS或Apache中的虛擬主機設置,可以直接使用英文域名,例如 unethost.com。然而,現在逐漸開始流行的中文域名,如”網站設計.com”,在IIS或Apache中的伺服器設置檔應如何填寫呢?畢竟UTF-8編碼的中文,在apache或是IIS的設置檔通常是不容許的。

答案是:
在進行設置之前要先把中文域名轉化成為PunyCode編碼,然後在設置檔裡填上中文域名所對應的PunyCode編碼(xn--5tz61dz4phe.com)即可。新的國際化域名的標准在網域名稱編碼上,為了保留向下兼容性及不影響現有的應用程序協議,因此將多國語言域名轉成ASCII編碼,而這種編碼稱為『punycode』。

這邊有一個可以轉碼的連結

Geo IP support

客戶問我,為什麼我的主機上,不能使用這個php函數 geoip_country_name_by_name?

當然是因為GeoIP的PECL預設沒有安裝導致的。本來是打算用WHM的功能,按幾個鈕就把GeoIP的PECL灌好的,結果讓我大失所望,灌不起來。查了一下,為什麼會灌不起來,根本的原因似乎是:如果要灌這個PECL的php extension,必須要先灌一個MaxMind的GeoIP資料庫,我想一想,太麻煩了,所以我就灌了一個替代方案給客戶。我灌了PEAR套件裡的Net_GeoIP給他。

PECL是C語言寫的extension,所以一有東西不對,就會無法編譯。PEAR基本上是用php寫的,一瞬間就灌好了。本來以為這樣子就結束了…結果,客戶回報我說,東西不能用。

不會吧? 有沒有搞錯?明明就是成功地安裝啊?

我查了一下,PEAR也是一樣有需要外部GeoIP資料庫的問題。只是說,有一個很大的差別是,PEAR的資料庫是由寫php程式的客戶,自己負責綁定。

嗯,就這一回吧,好主機商做到底。我放了一段testing code給客戶,而且也順便幫他把geoip的資料庫從網路上抓好。( 這個客戶看起來也不太會寫程式的樣子。冏 ~ )


<?
require_once "Net/GeoIP.php";

$geoip = Net_GeoIP::getInstance("./GeoIP.dat");

echo $_SERVER&#91;'REMOTE_ADDR'&#93;."
";
try {
echo $geoip->lookupCountryName($_SERVER['REMOTE_ADDR']);
} catch (Exception $e) {
// Handle exception
echo "exception";
}

?>