1

I would like to rewrite files that don't exist to a php handler. I am currently using this .htaccess file, but it doesn't work as I'd like:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /app/index.php?_url=/$1

When I have no files, it works; it redirects correctly for resource that does not exist to my app, and I am able to capture it.

When I have exactly matching file (e.g.: test.txt and I request /test.txt); it loads test.txt correctly.

However, when I have a partial match (e.g.: test.txt exists, but I request /test); it does not redirect at all. In fact, it gives me the standard Apache 404. I want this to actually rewrite to my app, so I can deal with the request in a different manner.

I'm using pretty much default apache 2.2.22 from Debian. Is there some configuration I am missing, or is this the intended behaviour of the rewrite? Is there a way to achieve what I want?

4

1 回答 1

1

我认为您MultiViews默认已在 Apache 中启用。尝试在 .htaccess 顶部添加这一行:

Options -MultiViews

使用MultiViewsApache 进行自己的重写,这通常与mod_rewrite

于 2013-11-09T09:37:14.980 回答