2

在 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 代码放在这里。

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

4

2 回答 2

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

于 2014-02-27T22:52:23.840 回答
0

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

Options +SymLinksIfOwnerMatch

帮助过我。

于 2020-07-02T17:18:54.020 回答