多个RewriteCond,这个代码如何工作?

我在* .conf文件中有这个(我从别人那得到这个,不知道是否有错误),我不太明白:

RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} mycompany.com RewriteRule ^$ http://mycompany.com/login [L] # we check if the .html version is here (caching) RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f # no, so we redirect to our front web controller RewriteRule ^(.*)$ index.php [QSA,L] 

我大致了解它的作用; 首先检查传入的请求是否是mycompany.com ,如果是,则redirect到http://mycompany.com/login

那么,下一个要检查的条件是什么? 有这个事实

 RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] 

来之前RewriteRule ^$ http://mycompany.com/login [L]令我困惑。

无论如何,重写上述脚本的RewriteCondRewriteRuleRewriteCondRewriteRule格式?

你有一个模糊的缩进你的configuration文件。

也许以下更清楚:

 RewriteEngine on RewriteBase / # If the requested hostname is mycompany # and no path segment was given, # redirect to /login RewriteCond %{HTTP_HOST} mycompany.com RewriteRule ^$ http://mycompany.com/login [L] # Add .html extension to any requested filename. RewriteRule ^([^.]+)$ $1.html [QSA] # Check if requested filename (now with .html # extension) exists, # otherwise redirect to front controller RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] 

我删除了

 RewriteRule ^$ index.html [QSA] 

因为这可以更容易地用DirectoryIndex指令完成。