我在 Apache2 服务器下编写了以下mod_rewrite规则并放入 .htaccess 文件中:
Options +FollowSymLinks
Options -Multiviews
RewriteEngine On
RewriteBase /db/
RewriteCond $1 !^(index.php|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
我的重写模块已启用:
root /var/www/db # a2enmod rewrite
Module rewrite already enabled
root /var/www/db # ls -al /etc/apache2/mods-enabled/rewrite.load
lrwxrwxrwx 1 root root 30 Mar 2 13:42 /etc/apache2/mods-enabled/rewrite.load -> ../mods-available/rewrite.load
.htaccess 文件在 apache2.conf
中启用:
AccessFileName .htaccess
当我尝试访问重写的 URL 时,它似乎不起作用:
Not Found
The requested URL /db/user/dashboard was not found on this server.
在我的 apache2 错误日志中:
File does not exist: /var/www/db/user
知道吗?
找到了解决方案,我忘记了站点 conf 中的AllowOverride
参数,它被设置为 none
并且应该all
:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>