Search code examples
.htaccessmod-rewrite

.htaccess mod_rewrite: difference between the -s and -f conditions


I have used the apache rewrite module a lot, but now I stumbled upon these two lines:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f 

The first line uses the -s condition. The second uses the -f condition. In the docs it reads:

For -f

Treats the TestString as a pathname and tests whether or not it exists, and is a regular file.

For -s

Treats the TestString as a pathname and tests whether or not it exists, and is a regular file with size greater than zero.

I found the two conditions using Julian Pömp’s htaccess generator for angular.

So, what is the use of the -s condition (file with size) if there is already the -f condition (file exists)? It seems a little redundant to both check for the existence of a file and for the existence of a file with a size greater than zero. All files will pass the -f condition so there seems to be no need for the -s condition check…


Solution

  • You're right, it's redundant. If I use both conditions it shouldn't matter if the file size is greater than 0 or not. I'll change it to only -f.