.htaccess在Apache2的PHPurl

我试图在Ubuntu 15.04上使用mod_rewrite for Apache映射任何URL,例如localhost/firstlocalhost/first.php

这是步骤。

  1. 使用(apt-get apache2,php5)安装Apache2,PHP5在Apache中启用PHP,所以phpinfo()打印适当的信息。
  2. a2enmod重写,重启apache
  3. /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 
  4. /var/www/html .htaccess

     RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.php [NC,L] 
  5. chmod 644 /var/www/html/.htaccess

  6. 重新启动Apache

但像/localhost/second这样的请求不会转换为second.php

  1. 编辑.htaccess ,最后一行改为RewriteRule ^second$ second.php 。 但没有成功。

  2. 在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)。