简体   繁体   English

为什么index.html优先于index.php?

[英]Why does index.html have priority over index.php?

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?

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 vs php filetype有什么好处。

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. 您可以对其进行编辑并使其符合您的需求。

@kuroir is right, that depends on the web server configuration, in Apache it's the DirectoryIndex : @kuroir是对的,这取决于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文件。

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". 在URL中输入Wordpress“index.php”被重定向到“index.html”。 It had nothing to do with the .htaccess. 它与.htaccess无关。 I finally found the solution in their forum. 我终于在论坛中找到了解决方案。 Wordpress modified the program a couple years ago to strip "index.php" from URLs. Wordpress几年前修改了该程序,从URL中删除“index.php”。 So then of course it goes to your default (usually index.html). 那么当然它会转到你的默认值(通常是index.html)。

To make it behave as you expect, you need to revert the change here: changeset 9203 . 要使其按预期运行,您需要在此处还原更改: changeset 9203 See Forum topic 请参阅论坛主题

那么它取决于您的托管服务提供商是的90%托管服务提供商优先使用index.html而不是index.php或任何其他扩展。

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重写来暴露扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM