.htaccess mod_rewrite: -s 和 -f 条件的区别
.htaccess mod_rewrite: difference between the -s and -f conditions
我经常使用 apache 重写模块,但现在我偶然发现了这两行:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
第一行使用-s条件。第二个使用 -f 条件。在 docs 中显示:
对于-f
Treats the TestString as a pathname and tests whether or not it exists, and is a regular file.
对于-s
Treats the TestString as a pathname and tests whether or not it exists, and is a regular file with size greater than zero.
我使用Julian Pömp’s htaccess generator for angular找到了两个条件。
那么,如果已经存在-f
条件(文件存在),那么-s
条件(文件大小)有什么用呢?检查文件是否存在和大小大于零的文件是否存在似乎有点多余。所有文件都将通过 -f
条件,因此似乎不需要 -s
条件检查……
你说得对,这是多余的。如果我同时使用这两个条件,那么文件大小是否大于 0 并不重要。我将其更改为仅 -f
.
我经常使用 apache 重写模块,但现在我偶然发现了这两行:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
第一行使用-s条件。第二个使用 -f 条件。在 docs 中显示:
对于-f
Treats the TestString as a pathname and tests whether or not it exists, and is a regular file.
对于-s
Treats the TestString as a pathname and tests whether or not it exists, and is a regular file with size greater than zero.
我使用Julian Pömp’s htaccess generator for angular找到了两个条件。
那么,如果已经存在-f
条件(文件存在),那么-s
条件(文件大小)有什么用呢?检查文件是否存在和大小大于零的文件是否存在似乎有点多余。所有文件都将通过 -f
条件,因此似乎不需要 -s
条件检查……
你说得对,这是多余的。如果我同时使用这两个条件,那么文件大小是否大于 0 并不重要。我将其更改为仅 -f
.