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

View this thread on steempeak.com
· @oflyhigh ·
$23.26
每天进步一点点:Ubuntu下修改Apache2默认网页(主页)
以往自己做网页都习惯用`index.html`或者`index.php`来为主页命名,用在cPanel虚拟主机上也没发现任何问题。但是从网上下载一组网页后,并放到Apache2+Ubuntu的环境下,却发现默认的网页没被加载。

![](https://steemitimages.com/DQmRkLq6rRew3mHfx4vYGWyqpC8wSebLPeC2iZCXAdpuGkR/image.png)
(图源 :[pixabay](https://pixabay.com/))

# 默认网页

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

比如打开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`,我们会得到类似如下内容:
>![](https://cdn.steemitimages.com/DQmaqFwL4hVyBznzDzU8h6UKteGADcy91WoNa2n7sJgjznM/image.png)

原来控制缺省网页是用的[DirectoryIndex 指令](https://httpd.apache.org/docs/2.4/mod/mod_dir.html),详情大家可以参考文末链接,这里就不再赘述了。

# 终极解决方法

知道了这点,解决上述问题就很简单了,把`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`自动加载啦。

# 相关链接

* [DirectoryIndex Directive](https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryindex)

----
<center><strong>Vote For Me As Witness</strong>
https://steemit.com/~witnesses type in **`oflyhigh`** and click ***`VOTE`***
[![](https://cdn.steemitimages.com/DQmX5NysqT44FBa3bhuWqQ69nAbseu8Nt5YQPn2pYejPVxA/image.png)](https://steemit.com/~witnesses)
[Vote @oflyhigh via Steemconnect](https://steemconnect.com/sign/account-witness-vote?witness=oflyhigh&approve=1)
<strong>Thank you!</strong></center>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 146 others
properties (23)
post_id79,897,348
authoroflyhigh
permlinkubuntu-apache2
categorycn
json_metadata{"tags":["cn","apache","index","ubuntu","seo"],"image":["https:\/\/steemitimages.com\/DQmRkLq6rRew3mHfx4vYGWyqpC8wSebLPeC2iZCXAdpuGkR\/image.png","https:\/\/cdn.steemitimages.com\/DQmaqFwL4hVyBznzDzU8h6UKteGADcy91WoNa2n7sJgjznM\/image.png","https:\/\/cdn.steemitimages.com\/DQmX5NysqT44FBa3bhuWqQ69nAbseu8Nt5YQPn2pYejPVxA\/image.png"],"links":["https:\/\/pixabay.com\/","https:\/\/eztk.net","https:\/\/www.eztk.net\/index.php","https:\/\/httpd.apache.org\/docs\/2.4\/mod\/mod_dir.html","https:\/\/httpd.apache.org\/docs\/2.4\/mod\/mod_dir.html#directoryindex","https:\/\/steemit.com\/~witnesses","https:\/\/steemconnect.com\/sign\/account-witness-vote?witness=oflyhigh&approve=1"],"app":"steemit\/0.1","format":"markdown"}
created2019-09-11 00:29:06
last_update2019-09-11 00:29:06
depth0
children4
net_rshares57,535,337,879,947
last_payout2019-09-18 00:29:06
cashout_time1969-12-31 23:59:59
total_payout_value11.742 SBD
curator_payout_value11.517 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,765
author_reputation1,148,153,621,496,884
root_title每天进步一点点:Ubuntu下修改Apache2默认网页(主页)
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (210)
@partiko ·
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!
👍  
properties (23)
post_id79,898,443
authorpartiko
permlinkre-ubuntu-apache2-20190911t013013
categorycn
json_metadata{"app":"partiko"}
created2019-09-11 01:30:15
last_update2019-09-11 01:30:15
depth1
children0
net_rshares24,718,243
last_payout2019-09-18 01:30:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length213
author_reputation39,204,266,552,701
root_title每天进步一点点:Ubuntu下修改Apache2默认网页(主页)
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@growupjv ·
$0.19
Just only need redirect 301 the default.html to index.html, and all will be solved :)
👍  
properties (23)
post_id79,902,739
authorgrowupjv
permlinkpxnjmv
categorycn
json_metadata{"tags":["cn"],"app":"steemit\/0.1"}
created2019-09-11 05:37:45
last_update2019-09-11 05:37:45
depth1
children1
net_rshares819,059,946,251
last_payout2019-09-18 05:37:45
cashout_time1969-12-31 23:59:59
total_payout_value0.097 SBD
curator_payout_value0.097 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length85
author_reputation33,113,112,148
root_title每天进步一点点:Ubuntu下修改Apache2默认网页(主页)
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@oflyhigh ·
It's really a good idea.👍
properties (22)
post_id79,908,792
authoroflyhigh
permlinkpxnygt
categorycn
json_metadata{"tags":["cn"],"app":"steemit\/0.1"}
created2019-09-11 10:58:09
last_update2019-09-11 10:58:09
depth2
children0
net_rshares0
last_payout2019-09-18 10:58:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length25
author_reputation1,148,153,621,496,884
root_title每天进步一点点:Ubuntu下修改Apache2默认网页(主页)
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@bowen11 ·
高手,看您发布的文章,被点赞那么多,获得美金不少??能问下到底怎么玩steem才真正能像你一样赚那么多美金吗!??真诚求教!?

来自于 [WhereIn Android] (http://www.wherein.io)
properties (22)
post_id79,962,955
authorbowen11
permlinkwherein-1568357989220
categorycn
json_metadata{}
created2019-09-13 06:59:51
last_update2019-09-13 06:59:51
depth1
children0
net_rshares0
last_payout2019-09-20 06:59:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length110
author_reputation3,557,223,159,170
root_title每天进步一点点:Ubuntu下修改Apache2默认网页(主页)
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000