mod_rewrite 没有工作,所以在修复它时得到 403 禁止
Posted
技术标签:
【中文标题】mod_rewrite 没有工作,所以在修复它时得到 403 禁止【英文标题】:mod_rewrite wasn't working so while fixing it getting 403 forbidden 【发布时间】:2014-03-19 02:13:31 【问题描述】:在 ubuntu 13.10 上,我使用的是 apache 2.4.x 。我遇到了mod_rewrite
的问题。我启用了该模块并重新启动了服务器,但 .htaccess 文件仍然无法正常工作,所以经过一番搜索,我从 *** 中读取了指向:http://smarttips.in/htaccess-redirect-not-working-apache/ 的答案
我在上面的链接中遗漏了第 2 点。所以我将该代码放在我的000-default.conf
文件中。
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
因为我使用的是 apache2.4+,所以在这里告诉:http://httpd.apache.org/docs/current/upgrading.html
Order allow, deny
Allow from all
到
Require all granted
这是我的 000-default.conf 文件中的代码:
<VirtualHost *:80>
# 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
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#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
</VirtualHost>
但是在从那个链接输入那个代码之后,现在服务器给出了 403 禁止,说:
You don't have permission to access /mysite/ on this server.
Apache/2.4.6 (Ubuntu) Server at localhost Port 80
所以不确定该 mod_rewrite 问题是否已解决,但现在也出现权限错误。 让我知道是否也需要将 .htaccess 代码放在这里。
所以知道我做错了什么吗?
【问题讨论】:
您目前在该目录中是否有 htaccess 文件,您是否尝试删除任何规则以查看它是否可以在没有它的情况下工作? @PanamaJack 是在var/www/mysite/
目录中
@Hafiz:你有没有机会启用 SELinux?
权限问题 => apache 用户有权访问文件?尝试 chmod 777 看看是否还有 403 错误
@elhostis 我试过了
【参考方案1】:
我只是删除了:
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
换成这个:
DocumentRoot /var/www
<Directory /var/www>
AllowOverride All
</Directory>
现在权限错误消失了,mod_rewrite 正在按预期工作。
【讨论】:
【参考方案2】:将此添加到<Directory /var/www/html>
Options +SymLinksIfOwnerMatch
帮了我。
【讨论】:
以上是关于mod_rewrite 没有工作,所以在修复它时得到 403 禁止的主要内容,如果未能解决你的问题,请参考以下文章
无法卸载或修复Microsoft Visual Studio 2015社区