2012年8月9日

使用BlueHos將主網域指向子目錄

使用Bluehost好處,除了價錢實惠,同時能架設多個獨立Domain網站。

一開始承租Bluehost,若是使用Joomla!架站,主網域原始設定是呈現於Public_html根目錄之中。然而隨著建立多個子目錄後,就會開始看起來有點亂,同時會發生使用其他網域指定到子目錄時,發生讀取不到圖片之問題。

為解決此問題,建議將根目錄底下,只存放子目錄就好,同時將主網域指定在其中一個子目錄中,如此一來根目錄不但資料清楚,也可以解決子目錄讀取不到圖片之問題。

解決方式:

請在public_html資料夾底下建立.htaccess文件(可用筆記本或notepad++建立),其貼上其內容如下:

# Bluehost.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]

其中請將藍字的example.com修改為您的主網域名稱,藍字subdirectory修改為你欲指定主網域的子目錄名稱。 若是使用joomla架站,請將index.html修改為index.php。

P.S 請注意.htaccess格式,若上傳FTP後呈現.htaccess.txt,請將.txt去除。

設定完成後,根目錄底下應該只有子目錄資料夾與.htaccess檔。

利用.htaccess解決主網域指向子目錄問題後,仍然有一個問題,瀏覽器上主網域仍然會呈現子目錄網址,如:twotrees.tw/twotrees1,若不想顯示子目錄網址,可參考這篇:修改configuration.php,讓子目錄網址不再顯示

0 意見:

張貼留言

或許您對其他文章有興趣

Related Posts Plugin for WordPress, Blogger...