乍一看,这似乎是一个重复的问题,但我在互联网上进行了 10 个小时的研究,尝试了几乎所有能找到的方法,但 mod rewrite 却毫无效果。互联网上的大多数帖子/教程都很旧,而且他们从那时起就没有更新过文章。
我可以看到phpinfo()
,我已成功加载该mod_rewrite
模块。
接下来我知道我必须更改AllowOverride None
为AllowOverride All
并对 Apache 的文件进行一些更改default.conf
。由于我没有文件,所以default.conf
我对 进行了这些更改000-default.conf
,但mod_rewrite
没有效果。我还更改了文件apache.conf
,但仍然没有效果。我更改了所有我能看到的文件,<Directory> </Directory>
但没有效果。
我的根目录不是/var/www
,事实上它是/var/www/html
。
这是我的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/html
# 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
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我怎样去mod_rewrite
上班?
答案1
问题解决了。这是 CakePHP 的问题。根目录的 .htaccess 文件没有与 cakePHP 源一起复制。
在 CakePHP 根目录中创建一个 .htaccess 文件,内容如下
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
参考:https://stackoverflow.com/questions/10835344/cakephp-doesnt-work-url-rewriting-on-ubuntu