如何使网站运行index.html文件? [英] How to make a website run the index.html file?

查看:1012
本文介绍了如何使网站运行index.html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚托管了一个网站.但是,当我要运行该网站时,它将打开该网站的索引(我使用FTP添加的文件列表,而不是Index.html页面).该如何解决?

I just hosted a website. But, when i want to run the website it opens the index of the website (list of files what i added using FTP and not the Index.html page). How to fix that?

请帮助...

推荐答案

如果您要在向您的网站域提出请求时显示index.html文件的内容,则假设它是domain.com,那么所有您要做的就是将index.html文件上传到服务器上正确的文档根目录.

If you want to display the contents of an index.html file when a request is made to your website domain, let's say it is domain.com, then all you have to do is to upload the index.html file to the correct document root directory on your server.

文档根目录是用于存储域名网站文件的文件夹.

The document root is the folder where the website files for a domain name are stored.

根据您的服务器配置,文档根目录的名称可能会有所不同,但是,它们的常规名称是这样的:

Document root directories might be named differently depending on your server configuration, however, they're conventionally named as such:

/www/
/public_html/

它们也可能位于另一个目录中,例如

They also might live within another directory such as

/home/myusername/public_html/ 

您的主域通常位于 www public_html 文件夹中.

Your primary domain is generally rooted in the www or public_html folder.

当有人尝试加载您的网站而没有手动键入文件名(例如index.php或index.html)时,服务器将尝试加载目录索引".目录索引是应该加载的文件的列表.

When someone tries to load your website and does not manually type in a file name (such as index.php or index.html), the server attempts to load the "directory index". The directory index is a listing of files it should load.

例如,如果键入domain.com(即不是domain.com/index.php),则服务器将尝试按以下顺序加载文件.如果找不到文件,则尝试加载列表中的下一个文件:

For example, if you type in domain.com (i.e: not domain.com/index.php), the server will attempt to load files in the following order. If a file is not found, then it tries to load the next file in the list:

http://domain.com/index.html
http://domain.com/index.htm
http://domain.com/index.php

...最后,如果您的服务器没有找到这些文件中的任何一个,则它仅返回目录中所有文件的列表. 查看图片

...and finally, if your server does not find any of these files, it then simply returns a listing of all of the files in the directory. See Image

为防止这种情况,应该创建一个 index.html 文件,并将其上传到服务器的文档根目录,如我们之前提到的.

To prevent this, one should create an index.html file and upload it to the server's document root directory as we mentioned before.

尝试使用简单的文本编辑器创建以下第一个.html文件,方法是将下面的html标记复制到新文件中,然后将其另存为index.html或在此处下载文件

Try creating your first .html file with a simple text editor by copying the html markup below into a new file and then save it as index.html or download the file here

<html>
<head>
<title>My website's first HTML5 page</title>
</head>
<body>
<h1>Welcome!</h1>
<p>Sorry, but our website is under development.</p>
</body>
</html>

继续并将 index.html 文件上传到服务器的文档根目录,然后尝试访问您的网站域.它可能会加载您的 index.html ,并且服务器现在将显示index.html文件的内容,而不是"DirectoryIndex文件列表".

Proceed and upload the index.html file to your server's document root directory, and then try to access your website domain. It will probably load your index.html and your server will now display the contents of index.html file instead of the "DirectoryIndex listing of files".

不起作用时:

如果您刚刚将index.html或index.php文件放置在服务器的文档根文件夹中,例如:/public_html/,但仍无法在请求到您的域时加载它来加载这些文件,您的服务器可能缺少"DirectoryIndex指令"的特定配置.

If you've just placed an index.html or index.php file on your server's document root folder, for example: /public_html/ and you're still not getting it to load these files upon a request to your domain, chances are your server is missing a specific configuration for the "DirectoryIndex Directive".

如果这没有发生,则可以在.htaccess文件中使用DirectoryIndex指令来指定自定义文件,或当访问者请求目录时Web服务器要查找的文件.要启用DirectoryIndex指令,请使用文本编辑器按如下所示创建/修改.htaccess文件.将文件名替换为您希望在用户请求服务器的文档根目录时显示的文件:

If that fails to happen, you can use the DirectoryIndex directive in an .htaccess file to specify a custom file or files that the web server looks for when a visitor requests a directory. To enable the DirectoryIndex directive, use a text editor to create/modify the .htaccess file as follows. Replace filename with the file that you want to display whenever a user requests the server's document root directory:

DirectoryIndex filename

您还可以指定多个文件名,然后Web服务器将搜索每个文件,直到找到匹配的文件.

You can also specify multiple filenames, and the web server will search for each file until it finds a match.

打开文本编辑器并复制以下示例指令,然后将其粘贴到新文件上:

DirectoryIndex index.php index.html index.htm

将文件另存为.htaccess

没有文件扩展名,只需将其命名为.htaccess即可,在文件扩展名的前面加一个点(.),以确保它是隐藏文件.

在此伪指令中,当访问者请求目录名称时,Web服务器将首先查找index.php文件.如果找不到index.php文件,则将查找index.html文件,依此类推,直到找到匹配项或用尽了要搜索的文件.

In this directive, when a visitor requests the directory name, the web server looks first for an index.php file. If it does not find an index.php file, it looks for an index.html file, and so on until it finds a match or runs out of files to search.

现在将.htaccess文件上传到服务器的文档根目录.

建议您重新启动服务器以使更改生效,尽管您可以尝试刷新目录以查看其是否有效.

It is recommended to restart the server in order to changes to take effect, although you could just try to refresh the directory to see if it works.

如果您完全控制了服务器,则可能会发现它很容易重新启动/重新加载.但是,如果您依靠共享托管服务,则可能没有足够的权限来创建.htaccess文件或自行重启服务器,这意味着您必须与托管服务提供商支持团队联系并要求他们提供服务.为您做到这一点.

If you've got full control over your server you might find it easy restart/reload it. However, if you rely on a shared hosting service, maybe you'll not have enough permission to create an .htaccess file or to restart the server on your own, meaning that you would have to contact your hosting provider support team and request them to do that for you.

我希望它能对您有所帮助.祝你好运.

I hope it helps you. Good luck.

这篇关于如何使网站运行index.html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆