如何更改 Apache 中的默认索引页面? [英] How do I change the default index page in Apache?

查看:28
本文介绍了如何更改 Apache 中的默认索引页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改浏览网站时显示的默认网页.我目前正在运行一个报告程序,它输出一个名为 index.html 的文件.我无法更改它对文件的调用.因此,我的着陆页必须称为其他名称.现在,当我浏览我的网站时,它会将我带到报告页面.

I would like to change the default web page that shows up when I browse my site. I currently have a reporting program running, and it outputs a file called index.html. I cannot change what it calls the file. Therefore, my landing page must be called something else. Right now, when I browse my site it takes me to the reporting page.

据我所知,无论你叫什么 index.html,它都会把它作为你的默认值.我想把它改成landing.html.我该怎么做?

From what I see, whatever you call index.html it will pull that up as your default. I want to change that to landing.html. How do I do this?

我是一个文件夹(折叠@首页).报告程序是 HFM.net.HFM 可以输出带有我当前折叠统计信息的 html 文件.它命名 html 文件索引.我不希望它成为我的默认主页.我想要一个类似菜单的着陆点,我可以在那里选择是否要查看我的统计数据或其他内容.该网站位于/home/tyler/Documents/hfm/website(landing.html 和 hfm 的 index.html 在这里).Apache2 位于其默认目录中.

I am a folder (Folding @ Home). The reporting program is HFM.net. HFM can output an html file with my current folding statistics. It names the html file index. I do not want that to be my default home page. I would like a menu-like landing where I can choose if I want to see my stats, or something else. The website is at /home/tyler/Documents/hfm/website (landing.html and hfm's index.html are here). Apache2 is in its default directory.

我也在运行 Ubuntu 13.04.

I'm also running Ubuntu 13.04.

推荐答案

我推荐使用 .htaccess.您只需要添加:

I recommend using .htaccess. You only need to add:

DirectoryIndex home.php

或您想要的任何页面名称.

or whatever page name you want to have for it.

编辑:基本的 htaccess 教程.

EDIT: basic htaccess tutorial.

1) 在要更改索引文件的目录中创建 .htaccess 文件.

1) Create .htaccess file in the directory where you want to change the index file.

  • 无扩展名
  • . 在前面,确保它是一个隐藏"文件
  • no extension
  • . in front, to ensure it is a "hidden" file

在那里输入上面的行.您可能会添加很多很多其他内容(用于网络字体/媒体文件的 AddTypes、用于标题的缓存、用于压缩的 gzip 声明等),但这一行声明了您的新主页"页面.

Enter the line above in there. There will likely be many, many other things you will add to this (AddTypes for webfonts / media files, caching for headers, gzip declaration for compression, etc.), but that one line declares your new "home" page.

2) 将服务器设置为允许读取 .htaccess 文件(可能只需要在您的本地主机上,如果您的托管服务默认允许它像大多数一样)

2) Set server to allow reading of .htaccess files (may only be needed on your localhost, if your hosting servce defaults to allow it as most do)

假设您有访问权限,请转到您的服务器已启用的站点位置.我运行 Debian 服务器进行开发,Debian/Ubuntu 的默认站点设置位于 /etc/apache2/sites-available/default.不确定您运行的是什么服务器,只需搜索可用站点"并进入默认"文档.在那里你会看到一个目录条目.将其修改为如下所示:

Assuming you have access, go to your server's enabled site location. I run a Debian server for development, and the default site setup is at /etc/apache2/sites-available/default for Debian / Ubuntu. Not sure what server you run, but just search for "sites-available" and go into the "default" document. In there you will see an entry for Directory. Modify it to look like this:

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

然后重启你的apache服务器.同样,不确定您的服务器,但 Debian/Ubuntu 上的命令是:

Then restart your apache server. Again, not sure about your server, but the command on Debian / Ubuntu is:

sudo service apache2 restart

从技术上讲,你只需要重新加载,但我重新启动只是因为我觉得像这样完全刷新更安全.

Technically you only need to reload, but I restart just because I feel safer with a full refresh like that.

一旦完成,您的站点应该会读取您的 .htaccess 文件,并且您应该拥有一个新的默认主页!附带说明,如果您有一个运行站点的子目录(如管理部分或其他内容),并且您希望该目录有一个不同的主页",则只需插入另一个 .htaccess 文件位于该子站点的根目录中,它将覆盖父站点中的声明.

Once that is done, your site should be reading from your .htaccess file, and you should have a new default home page! A side note, if you have a sub-directory that runs a site (like an admin section or something) and you want to have a different "home page" for that directory, you can just plop another .htaccess file in that sub-site's root and it will overwrite the declaration in the parent.

这篇关于如何更改 Apache 中的默认索引页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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