我已经从Wordpress中解除了大部分,所以像say /search
或/list
这样的域名的任何path都被定向到/index.php
。 很好,工作。
但是,如果请求的文件存在于文档根目录中 ,则不应该这样做。 所以,如果我请求/exists.php
它应该运行该脚本。 相反,它忽略了文件系统上的文件,并继续为index.php
服务。
<VirtualHost *:80> DocumentRoot /home/sites/dev ServerName dev.vbox RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . /index.php ErrorLog /var/log/apache2/dev.error.log </VirtualHost>
我已经通过mod_rewrite文档和各种谷歌search结果,但我没有看到我的重写条件有什么问题。 如果请求的文件名是文件或目录,请不要redirect到/index.php
。
我已经cd
到doc根目录,并列出了该目录的内容,我请求的文件存在。 我的apache访问日志有/exists.php
条目。
文档根目录是安装在我的Mac上的目录,服务请求的虚拟机是Ubuntu安装。
尝试%{LA-U:REQUEST_FILENAME}
而不是%{REQUEST_FILENAME}
。 在请求被映射到文件系统之前需要LA-U前缀。
编辑:
没有在我的第一个通过它赶上,你也需要改变的第一个参数为RewriteRule像这样:
<VirtualHost *:80> DocumentRoot /home/sites/dev ServerName dev.vbox RewriteEngine On RewriteCond %{LA-U:REQUEST_FILENAME} !-d RewriteCond %{LA-U:REQUEST_FILENAME} !-f RewriteRule .* /index.php ErrorLog /var/log/apache2/dev.error.log </VirtualHost>
我结束了添加另一个重写条件,所以我工作的虚拟主机看起来像这样:
<VirtualHost *:80> DocumentRoot /var/www/public_html ServerName domain.com RewriteEngine On RewriteCond %{REQUEST_FILENAME} !^.*\.(php)$ [nocase] RewriteRule . /index.php </VirtualHost>