一、想要設定Apache伺服器中每一個網站預設開啟首頁index的順序,可依下列方式修改
1.Windows版本(例如:httpd-2.2.23-win32、httpd-2.4.3-win32)
apache安裝目錄/conf/httpd.conf
找到下列文字,調整與加上你要的首頁index頁面
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.html index.php index,xhtml
</IfModule>
2.Unix版本(例如:apache2 2.2.22-1ubuntu1.2)
apache安裝目錄/mods-enabled/dir.conf
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm /cgi-bin/index.pl
</IfModule>
3.其他版本
請找尋httpd.conf或apache2.conf檔案,找到DirectoryIndex參數,
並依需求新增或刪除或調整您要的首頁順序。
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
二、想要設定Apache伺服器中每一個網站預設開啟首頁index的順序,可依下列方式修改
apache官方說明文件範例:
apache 2.2x版本
範例A跟B都是一樣的先找尋index.html,若找不到index.html再去尋找index.php
# Example A: Set index.html as an index page, then add index.php to that list as well.
<Directory /foo>
DirectoryIndex index.html
DirectoryIndex index.php
</Directory>
# Example B: This is identical to example A, except it's done with a single directive.
<Directory /foo>
DirectoryIndex index.html index.php
</Directory>
apache 2.4版本
範例A跟B都是一樣的先找尋index.html,若找不到index.html再去尋找index.php
範例C預設首頁只有index.php,利用disabled關閉了DirectoryIndex的功能,所以這個站台並不會去找尋index.html
# Example A: Set index.html as an index page, then add index.php to that list as well.
<Directory /foo>
DirectoryIndex index.html
DirectoryIndex index.php
</Directory>
# Example B: This is identical to example A, except it's done with a single directive.
<Directory /foo>
DirectoryIndex index.html index.php
</Directory>
# Example C: To replace the list, you must explicitly reset it first:
# In this example, only index.php will remain as an index resource.
<Directory /foo>
DirectoryIndex index.html
DirectoryIndex disabled
DirectoryIndex index.php
</Directory>
每次修改完成,一定要重新啟動apache再測試
參考資料:
http://httpd.apache.org/docs/2.0/mod/mod_dir.html
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex
http://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryindex
留言列表