views:

192

answers:

1

I have this apache rewrite rule:

  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]

The only thing I can make sense of is if it's mycompany.com, then the script will redirect to http://mycompany.com/login. If not, then ...

I can't figure out already.

Any idea what does the above script say?

+1  A: 

Something quite interesting, not easy to understand. A google search on the comment texts inside the code gave interesting results: http://www.google.com/search?q=%22%23+we+check+if+the+.html+version+is+here+%28caching%29%22

Edit: if we look at the last lines and knowing that Symfony uses caching (it creates local files with .html extension in the same directories as the URL shows 'em) I can try to explain the lines here

If the requested url is something like http://yoursite.com/blabla/ we try to open an index.html file in that directory. If the file is not there, another cycle of rewriting will happen and the last Cond will be hit (where the file does not exist)

RewriteRule ^$ index.html [QSA]

If something more is in the url, like http://yoursite.com/blabla/blblbl, try to find a file blblbl.html

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

This is the collector of all urls that did not match any of the previous rules or the cached file did not exist:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
naivists