在apache2中启用.htaccess
这可能与Ubuntu本身没有直接关系,但目录树在这里有所不同,我有点困惑。
我有一个网站,我正在尝试运行它加载正常,但它严重依赖URL重写我没有得到因为.htaccess指令可能没有在我的安装中启用。 我已经按照Ubuntu.com上的文章在我的apache2上启用了.htaccess文件,但我无法关注它,因为它告诉我要更改的文件不存在于它告诉我去的文件夹中。
这是最接近default
文件名 – 000-default.conf
:
# The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, eg #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我在这里看不到任何块。
如何启用.htaccess文件? 我每个项目都需要它们。
添加到VirtualHost:
AccessFileName .htaccess (.htaccess is the default filename) ... Options Indexes FollowSymLinks Includes AllowOverride All Order allow,deny Allow from all ...
然后重启apache:
service apache2 restart
要检查它是否有效,请将此行添加到.htaccess:
ErrorDocument 404 /error404.html
对于错误404(找不到页面),您的浏览应打开自定义错误页面,在本例中为error404.html
sudo -i sudo nano /etc/apache2/apache2.conf
如果你的ubuntu 80端口登陆/var/www/html
(仔细看看它不是 /var/www/
)
添加此块:
AllowOverride All