Apache,重写/重定向所有到index.php-请求的文件名不是空的

Apache,重写/重定向所有到index.php-请求的文件名不是空的,apache,.htaccess,redirect,mod-rewrite,Apache,.htaccess,Redirect,Mod Rewrite,我想将所有内容转发到index.php,除非没有指定任何文件(请求的文件名),或者URI为空,或者采用一个/ 我尝试过在.htaccess-文件中将所有内容重写/重定向到index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php/$1 [QSA] 如果我调用,test.php的内容将显示(!-f) 下一次尝试:检查,如果请求的文件不是index.php,然后重定向到index.php RewriteCo

我想将所有内容转发到index.php,除非没有指定任何文件(请求的文件名),或者URI为空,或者采用一个
/

我尝试过在
.htaccess
-文件中将所有内容重写/重定向到index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [QSA]
如果我调用,test.php的内容将显示(!-f)

下一次尝试:检查,如果请求的文件不是index.php,然后重定向到index.php

RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^(.*)$ /index.php/$1 [QSA,R=301]
RewriteCond %{REQUEST_FILENAME} !^$
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^(.*)$ /index.php/$1 [QSA,R=301]
好的,这样行。但是我想通过请求的空文件进行重定向

下一次尝试:如果请求的文件不是空的并且请求的文件不是index.php,则重定向

RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^(.*)$ /index.php/$1 [QSA,R=301]
RewriteCond %{REQUEST_FILENAME} !^$
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^(.*)$ /index.php/$1 [QSA,R=301]
如果我称它工作正常,请重定向到index.php/test.php:D

如果我调用或将其重定向到index.php。 但是我想通过请求的空文件进行重定向

更新(1) 我现在在.htaccess中有了这个

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^(.*)$ / [QSA,R=301]
#this redirect all files to root

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php/$1 [QSA,L]
#this rewrite on server side to index.php
这不管用<代码>http://my.dom/test.php被重定向到
http://my.dom/
。但是第二条规则会产生一个内部(550)错误(每次重定向)。我给第一部分加了一个新条件

RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_URI} !^/.*$
RewriteRule ^(.*)$ / [QSA,R=301]
#this redirect all files to root
通过此:
http://my.dom/test.php
不重定向


请告诉我我的错误在哪里。也许还有一些解决办法


因为它不是一个文件,/指向你的根目录。使用请求文件名变量无法与根目录匹配。要将主页从规则中排除,只需将正则表达式模式更改为(.+)

或者您可以使用以下规则

RewriteEngine on

RewriteRule ((?!index\.php).+) /index.php/$1 [L]

为了让您知道哪里出了问题,并帮助您理解,您几乎已经犯了错误,但您需要对两种情况都使用
REQUEST\u URI
,这是您在第一句话中说的。另外,为了防止重定向,您需要删除301重定向,它应该是
[QSA,L]
,这应该是
RewriteCond%{REQUEST_URI}^/$重定向设置为OK。如果URL-则应重定向到,而不是重写。通过重写,客户端的URL不会更改。我已经更新了我的尝试。