为什么 index.html 优先于 index.php?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7873634/
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
Why does index.html have priority over index.php?
提问by Akos
I have a website on a server. The homepage is example.com/index.php .
我在服务器上有一个网站。主页是 example.com/index.php 。
OK, I uploaded an index.html named file to the server (the root dir) and when I typed in my site's domain into the browser's URL bar, I was suprised, because the index.html page loaded.
好的,我将一个名为 index.html 的文件上传到服务器(根目录),当我在浏览器的 URL 栏中输入我站点的域时,我很惊讶,因为加载了 index.html 页面。
(example.com->example.com/index.html) So not what I wanted.
(example.com->example.com/index.html) 所以不是我想要的。
My question: Why did that happen? Why does index.html have advantage over index.php?
我的问题:为什么会这样?为什么 index.html 比 index.php 有优势?
回答by MarioRicalde
It really depends on the Server you're using. This is a matter of configuration. It's not that there's any advantage from using html vs php filetype.
这实际上取决于您使用的服务器。这是配置问题。并不是说使用 html 与 php 文件类型有什么优势。
You could say that the .html
variation takes precedence due to the fact that it's the most basic web format.
您可以说.html
变体优先,因为它是最基本的 Web 格式。
If you're using Apache, just check the default .htaccess
setup:
如果您使用的是 Apache,只需检查默认.htaccess
设置:
DirectoryIndex index.html index.shtml index.php index.htm default.html Default.htm default.html Default.html default.shtml Default.shtml page1.html index.pl index.cgi index.php3 index.phtml home.htm home.html home.shtml index.wml
You can edit that and make it fit your needs.
您可以编辑它并使其适合您的需要。
回答by Alix Axel
@kurtheitroad is right, that depends on the web server configuration, in Apache it's the DirectoryIndex
:
@kurtheitroad 是对的,这取决于 Web 服务器配置,在 Apache 中它是DirectoryIndex
:
DirectoryIndex index.html index.php index.cgi
That will give priority to .html
files over .php
files, and priority to .php
files over .cgi
files.
这将给予优先考虑.html
文件过.php
的文件,并优先.php
对文件.cgi
的文件。
回答by Joe
I know this is old and has been accepted but I want to add to this in case someone else has this problem.
我知道这是旧的并且已被接受,但我想补充一下,以防其他人遇到这个问题。
I came here when looking for a solution to the same problem. Entering the Wordpress "index.php" into the URL got redirected to "index.html". It had nothing to do with the .htaccess. I finally found the solution in their forum. Wordpress modified the program a couple years ago to strip "index.php" from URLs. So then of course it goes to your default (usually index.html).
我是在寻找相同问题的解决方案时来到这里的。在 URL 中输入 Wordpress“index.php”被重定向到“index.html”。它与 .htaccess 无关。我终于在他们的论坛中找到了解决方案。Wordpress 几年前修改了该程序以从 URL 中删除“index.php”。那么当然它会转到您的默认值(通常是 index.html)。
To make it behave as you expect, you need to revert the change here: changeset 9203. See Forum topic
要使其按预期运行,您需要在此处还原更改: changeset 9203。见论坛主题
回答by Robert
The biggest issue, as with all types of development, is maintenance. If you decide to change technology then by exposing the file extension you are setting yourself up for a lot of work - not to mention the security aspects of broadcasting your choice. The best situation is to avoid exposing extensions by using url rewriting.
与所有类型的开发一样,最大的问题是维护。如果您决定改变技术,那么通过公开文件扩展名,您将为自己做好大量工作——更不用说广播您选择的安全方面了。最好的情况是避免通过使用 url 重写来暴露扩展。
回答by Robert
Well it depends on your hosting provider well yes 90% hosting provider gives priority to index.html instead of index.php or any other extention.
嗯,这取决于您的托管服务提供商,是的,90% 的托管服务提供商优先考虑 index.html 而不是 index.php 或任何其他扩展。