我有以下重写设置:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^api/?.*$ api.php [NC,L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^.*$ web.php [L]我想要的是让api.php或web.php (它们自己进行路由)捕获非文件和目录,其余的则返回文件或目录。但是,被mod_rewrite视为''的主路由'/'没有被捕获-我猜这是因为/是一个目录-根。
我如何解决这个问题,使其在保持目录可访问的同时通过web.php?
发布于 2011-05-03 14:37:02
首先,您需要将规则中的REQUEST_URI更改为REQUEST_FILENAME。请参阅http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond
REQUEST_URI:在HTTP请求行中请求的资源。
REQUEST_FILENAME:与请求匹配的文件或脚本的完整本地文件系统路径。
然后,添加另一个规则:
RewriteCond %{REQUEST_URI} /
RewriteRule .* web.php [L]因此,最终结果将是:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/?.*$ api.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)? web.php [NC,L]
RewriteCond %{REQUEST_URI} /
RewriteRule .* web.php [L]发布于 2011-05-02 07:24:00
语法: RewriteBase URL-path
URL-path可以是root相对路径或为空。空的URL路径值意味着规则库将等于网站根。
https://stackoverflow.com/questions/5852095
复制相似问题