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
SEF – unethost無限空間虛擬主機 技術分享部落格

Search engine friendly URL

大約今年三月時,我把整個官網整合了whmcs系統。http://unethost.com/

這個whmcs有個功能叫做 Search engine friendly URL support,簡稱為SEF,這個是什麼意思呢?

如果不勾選這個選項的話,在knowledge base新增的文章,它的URL就會長成這個德性:
http://support.unethost.com/knowledgebase.php?action=displayarticle&id=18

很明顯可以知道這個連結是一個動態產生的頁面。然而各家的搜尋引擎google, yahoo對於分數的計算,都是比較喜歡靜態的頁面。所以,我就把這個選項勾了,然後,上頭那個連結就自動轉換成:
http://support.unethost.com/knowledgebase/18/web-template.html

到這裡為止,世界是和平的^^。然而,不和平的在後面。很快地,我就發現了很討人厭的問題,如果我新增的文章的title,全部是中文時,就會長出下方這種會爛掉的link,會爛掉的原因,似乎是因為會造成mod rewrite的loop。
http://support.unethost.com/knowledgebase/23/.html

這是為什麼呢?因為,whmcs的php在生成內部連結時,大概是長成這樣子的語法:
{if $seofriendlyurls}
announcements/{$id}/{$urlfriendlytitle}.html
{else}
announcements.php?id={$id}

其中,這個$urlfriendlytitle,被whmcs的設計者(這些死老美!!) 設計成,不考慮多語言的case,如果你的title本來是全部用中文寫的,它就真的給你丟出空字串。然後你的連結就會爛了。所以我對上述的code作了修改:


$urlfriendlytitle}.html
改成了
$urlfriendlytitle}-seo.html

這實在是個很暴力/很醜的改法。不過,先湊合著用就好~。(SEO做到1000分,服務不好還是不會有客戶)  這樣子,就不會生成.html的這種,之後會造成loop問題的連結。而是會形成:http://support.unethost.com/knowledgebase/23/-seo.html
我只要求.html之前,至少有一些字串就好了~ 不要求太多。

接下來,我就要開始動手術了:一次修改大量的.php檔,一口氣解決問題。來一個指令吧:

find . -name *.tpl  -exec grep -l urlfriendlytitle {} \;

把所有疑似有罪的檔案全部都抓出來修改。就這樣子,我讓官網的一些動態頁面,全數變成了SEF(Search Engine Friendly) url