我有網站http://mywebsite.com如果我打這個URL,它將index.php和index.html作爲默認頁面。我如何使home.php成爲默認頁面。 我都試過,但沒有把下面的代碼的public_html如何使默認頁面home.php,而不是index.html和index.php
DirectoryIndex home.php index.html index.php
我有網站http://mywebsite.com如果我打這個URL,它將index.php和index.html作爲默認頁面。我如何使home.php成爲默認頁面。 我都試過,但沒有把下面的代碼的public_html如何使默認頁面home.php,而不是index.html和index.php
DirectoryIndex home.php index.html index.php
的.htaccess文件裏面工作,您只需要在home.php
你DirectoryIndex
,使之工作。請記住,這是你的根項目的.htaccess文件中使用:
DirectoryIndex home.php
您需要AllowOverride +Indexes
在httpd.conf
能在.htaccess
使用DirectoryIndex
。
除非是,絕對最簡單的方法來重定向(無根訪問Apache的配置和模塊)是把這個作爲index.html
:
<!doctype html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=home.php">
</head>
<body>
</body>
</html>
不錯的解決方案... – Dev
只是嘗試重寫/index.html
和/index.php
到/home.php
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.(html|php)
RewriteRule ^(.*) /home.php
我想,http://stackoverflow.com/a/15779237/2007055是正確的。 – 5ervant
DirectoryIndex指令適用於所有的子文件夾,如果你想爲每個目錄設置不同的文件,你可以使用mod-rewrite。
要設置/file.html作爲根目錄處理,你可以在你的htaccess的頂部使用:
RewriteEngine on
RewriteRule ^$ /file.html [L]
要設置不同勢文件作爲指數的子文件夾,使用此:
RewriteEngine on
RewriteRule ^subfolder/$ /myfile.html [L]
它適用於所有子文件夾。我只想僅應用於根文件夾。 – CodeManiac