每天进步一点点:Ubuntu下修改Apache2默认网页(主页)

in #cn5 years ago

以往自己做网页都习惯用index.html或者index.php来为主页命名,用在cPanel虚拟主机上也没发现任何问题。但是从网上下载一组网页后,并放到Apache2+Ubuntu的环境下,却发现默认的网页没被加载。


(图源 :pixabay)

默认网页

所谓的默认网页,就是我打开网址后不添加任何文件名,网站自动加载的页面。

比如打开https://eztk.net 会自动加载 https://www.eztk.net/index.php 这个index.php就是默认网页,在根目录下也被叫做网站的首页或者主页。

但是我下载的一组网页竟然用default.html做为主页,然后上传打开网址后,竟然没有被自动加载,这就尬尴了。

初级解决方法

一种解决方法是把default.html重命名为index.html,但是这样可能破坏其它关联页面到这个网页的链接。

另外一种方法是复制一个index.html包含与default.html同样的内容,但是这样做可能影响SEO被搜索引擎降权。

DirectoryIndex指令

既然上述方法不理想,那么就要尝试从Apache下手解决了,要想解决这个,首先要知道Apache如何查找默认网页的。

在Apache2目录下搜索index.html,我们会得到类似如下内容:

原来控制缺省网页是用的DirectoryIndex 指令,详情大家可以参考文末链接,这里就不再赘述了。

终极解决方法

知道了这点,解决上述问题就很简单了,把default.html加入到DirectoryIndex 指令下(捎带删除我从来不用的),并重启Apache即可。

<IfModule mod_dir.c>
        DirectoryIndex index.html index.php index.htm default.html
</IfModule>

重新加载Apache2

sudo systemctl reload apache2

或者重启Apache2

sudo systemctl restart apache2

哈哈,不用重命名也不用弄分身COPY,访问站点URL,default.html自动加载啦。

相关链接


Vote For Me As Witness
https://steemit.com/~witnesses type in oflyhigh and click VOTE

Vote @oflyhigh via Steemconnect
Thank you!

Sort:  

Just only need redirect 301 the default.html to index.html, and all will be solved :)

It's really a good idea.👍

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.01% upvote! Together, let’s change the world!

高手,看您发布的文章,被点赞那么多,获得美金不少??能问下到底怎么玩steem才真正能像你一样赚那么多美金吗!??真诚求教!?

来自于 [WhereIn Android] (http://www.wherein.io)

Coin Marketplace

STEEM 0.28
TRX 0.13
JST 0.032
BTC 60725.43
ETH 2900.91
USDT 1.00
SBD 3.59