如何制作默认页面 home.php 而不是 index.html 和 index.php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15779198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to make default page home.php instead of index.html and index.php
提问by CodeManiac
I have website http://mywebsite.comIf I hit this URL it take index.php and index.html as default page. How can I make home.php as default page. I have tried this but not working by placing following code inside .htaccess file of public_html
我有网站http://mywebsite.com如果我点击这个 URL,它将 index.php 和 index.html 作为默认页面。如何将 home.php 设为默认页面。我已经尝试过这个,但没有通过将以下代码放在 public_html 的 .htaccess 文件中来工作
DirectoryIndex home.php index.html index.php
回答by Eli
You just need home.phpin your DirectoryIndexto make it works. Remember that this is using in .htaccess file of your root project:
你只需要home.php在你的DirectoryIndex让它工作。请记住,这是在根项目的 .htaccess 文件中使用的:
DirectoryIndex home.php
回答by Amadan
You need AllowOverride +Indexesin your httpd.confto be able to use DirectoryIndexin .htaccess.
你需要AllowOverride +Indexes在你httpd.conf能够使用DirectoryIndex的.htaccess。
Barring that, the absolutely easiest way to redirect (without the root access to Apache config and modules) is putting this as index.html:
除此之外,最简单的重定向方法(没有对 Apache 配置和模块的 root 访问权限)是将其设置为index.html:
<!doctype html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=home.php">
</head>
<body>
</body>
</html>
回答by starkeen
DirectoryIndex directive applies to all subfolders, if you want set diffrent files for each directories, you can use mod-rewrite.
DirectoryIndex 指令适用于所有子文件夹,如果要为每个目录设置不同的文件,可以使用 mod-rewrite。
To set /file.htmlas root directory handler, you can use this at the top of your htaccess :
要将/file.html设置为根目录处理程序,您可以在 htaccess 顶部使用它:
RewriteEngine on
RewriteRule ^$ /file.html [L]
To set a diffrent file as index for a subfolder, use this :
要将不同的文件设置为子文件夹的索引,请使用以下命令:
RewriteEngine on
RewriteRule ^subfolder/$ /myfile.html [L]
回答by 5ervant
Just try to rewrite /index.htmland /index.phpinto /home.php
尝试重写/index.html并/index.php写入/home.php
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.(html|php)
RewriteRule ^(.*) /home.php

