views:

14

answers:

1

i want to understand at least abit on how the .htaccess works. i am using the .htaccess from zend framework (since thats what i use often)

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

1st line to set an environment variable, ok simple enuf, but what do the subsequent lines do? whats the -s -l [NC,L] etc for. from the apache docs i can see that

  • -s - refers to a "regular file with a size". just curious is there a non-regular file?
  • -l - refers to a symbolic link - whats that
  • -d - refers to a directiory
  • REQUEST_FILENAME - full local filesystem path to the file or script matching the request
  • REQUEST_URI - resource requested in the HTTP request line.

assuming i browsed to "http://localhost/some/path/here". what will REQUEST_FILENAME & REQUEST_URI equals to?

anyway, i interpret the rules currently as

  • if the request is for a file with size OR
  • if the request is for a link OR
  • if the request is for a directory
  • ... do something ...
  • what does RewriteRule ^.*$ - [NC,L] do?
  • then i guess route everything matching the rules above to index.php
A: 

If the URL points to a real file/dir/link, serve the URL as is (the first RewriteRule line does not change the URL at all). Else, redirect to index.php.

Sjoerd
does the 1st `RewriteRule` do anything then?
jiewmeng
The first rule does not rewrite the URL, but it prevents that the second RewriteRule is used. Thus, any URL which matches the RewriteConds is *not* redirected to index.php.
Sjoerd