【问题标题】:Changing default home page in Apache2更改 Apache2 中的默认主页
【发布时间】:2018-11-09 06:50:42
【问题描述】:
我的目录结构是
app
- index.php
home
- index.php
index.php
我希望用户在每次访问 http://example.com 时查看 home/index.php,但如果用户也使用导航进行导航,我也希望用户访问 http://example.com。
我的问题是,我可以配置 apache 以使网站默认主页而不是根目录。我不介意用户是否第一次被重定向到 home/index.php。
【问题讨论】:
标签:
php
apache2
configure
【解决方案1】:
当然可以。只需设置一个 vhost 以使 DocumentRoot 语句指向您希望根目录成为的任何内容。
例如:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/my_site/home"
</VirtualHost>
但请注意,在此之后,DocumentRoot 路径中的任何 updir 都将超出 Apache 的范围。但是,您可以使用 PHP 中的 require/include 函数包含文件 updir。
您可能还需要一个 Directory 语句来指定对该目录的访问权限。一个例子可以是:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/my_site/home"
<Directory "/var/www/my_site/home">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
同时不要忘记在对 vhost 配置文件进行任何更改后重新启动 Apache。