mod_rewrite没有工作,所以修复它被禁止403

时间:2014-02-19 00:55:18

标签: apache .htaccess mod-rewrite apache2.4

在ubuntu 13.10上我使用的是apache 2.4.x.我遇到mod_rewrite的问题。我启用了该模块并重新启动了服务器,但.htaccess文件仍然无法正常工作,所以经过一些搜索,我从stackoverflow中读到了一个回答: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代码,请告诉我。

所以我知道我做错了什么?

2 个答案:

答案 0 :(得分:0)

我只是删除了:

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正在按预期工作。

答案 1 :(得分:0)

将此添加到<Directory /var/www/html>

Options +SymLinksIfOwnerMatch

帮助了我。