我试图在Ubuntu 15.04上使用mod_rewrite for Apache映射任何URL,例如localhost/first到localhost/first.php 。
这是步骤。
phpinfo()打印适当的信息。 在/etc/apache2/sites-enabled/000-default.conf ,在适当的位置添加以下内容。
<VirtualHost *:80> <Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost> -- Restart Apache
/var/www/html .htaccess ,
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.php [NC,L]
chmod 644 /var/www/html/.htaccess
但像/localhost/second这样的请求不会转换为second.php 。
编辑.htaccess ,最后一行改为RewriteRule ^second$ second.php 。 但没有成功。
在Apache error.log中,我看到错误:
AH00687:协商:find匹配请求的文件:/ var / www / html / second(无法协商)。
有人可以帮忙吗?
Options Indexes FollowSymLinks MultiViews
MultiViews选项可能会导致此问题。 这应该被删除。 MultiViews (mod_negotiation的一部分)将尝试通过testing在该目录中find的各种文件在内部重写/file ( /file<.ext>系统上存在某些/file<.ext> )的请求,并提供与适当的mime-types。 这发生在 mod_rewrite 之前,并可能导致冲突(因为你正在尝试做类似的事情与mod_rewrite)。