如何配置apache以允许重写目录规则


How to configure apache to allow rewrite rules for directories?

我在htaccess中有一些配置:

RewriteEngine On
RewriteRule ^(.*)$ /index.php [L,NC,QSA]

所有URL重定向到/index.php

但如果文件夹存在,它将转到文件夹,而不是/index.php

为什么?

我尝试了这个解决方案:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . index.php [QSA,L]

但这就像前面的例子一样,转到directory=(

试试这个

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php

RewriteEngine On
RewriteCond %{REQUEST_URI} !-f
RewriteRule (.*)  index.php [QSA]

使用类似的东西:

#turn rewrite engine on
RewriteEngine On
#specify your base
RewriteBase /
#make sure, your index.php won't be rewritten
RewriteRule ^index.php - [L]
#rewrite everything else
RewriteRule ^(.*)$ index.php?para=$1 [QSA,L]

但如果文件夹存在,它将转到文件夹,而不是/index.php

尝试禁用MultiViews–在这种情况下,它通常会产生干扰。

Options -MultiViews

http://httpd.apache.org/docs/2.2/mod/core.html#options
http://httpd.apache.org/docs/2.2/mod/mod_negotiation.html#multiviews