【发布时间】:2013-03-24 15:18:38
【问题描述】:
我有网站http://mywebsite.com 如果我点击此 URL,它将 index.php 和 index.html 作为默认页面。如何将 home.php 作为默认页面。 我已经尝试过了,但通过将以下代码放在 public_html 的 .htaccess 文件中没有工作
DirectoryIndex home.php index.html index.php
【问题讨论】:
我有网站http://mywebsite.com 如果我点击此 URL,它将 index.php 和 index.html 作为默认页面。如何将 home.php 作为默认页面。 我已经尝试过了,但通过将以下代码放在 public_html 的 .htaccess 文件中没有工作
DirectoryIndex home.php index.html index.php
【问题讨论】:
您只需要在您的DirectoryIndex 中添加home.php 即可使其正常工作。请记住,这是在根项目的 .htaccess 文件中使用的:
DirectoryIndex home.php
【讨论】:
您需要在httpd.conf 中使用AllowOverride +Indexes 才能在.htaccess 中使用DirectoryIndex。
除此之外,最简单的重定向方法(没有对 Apache 配置和模块的 root 访问权限)是将其设置为 index.html:
<!doctype html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=home.php">
</head>
<body>
</body>
</html>
【讨论】:
DirectoryIndex 指令适用于所有子文件夹,如果你想为每个目录设置不同的文件,你可以使用 mod-rewrite。
要将 /file.html 设置为根目录处理程序,您可以在 htaccess 顶部使用它:
RewriteEngine on
RewriteRule ^$ /file.html [L]
要将不同的文件设置为子文件夹的索引,请使用:
RewriteEngine on
RewriteRule ^subfolder/$ /myfile.html [L]
【讨论】:
只需尝试将/index.html 和/index.php 重写为/home.php
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.(html|php)
RewriteRule ^(.*) /home.php
【讨论】: