I don't see any posts discuss the differences between REQUEST_URI and REQUEST_FILENAME, while I see many posts use them interchangeably.
I turned on the mod_rewrite log (LogLevel alert rewrite:trace8), replaced REQUEST_FILENAME with REQUEST_FILENAME, looked up the rewrite log in each configuration, and the rewriting process are exactly the same.
So my question is:
Are they the same under 99% circumstances?
I didn't say 100% because I see from doc(https://httpd.apache.org/docs/current/mod/mod_rewrite.html) mentioning an exception for REQUEST_URI related to something called AcceptPathInfo.
REQUEST_FILENAME
The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time
REQUEST_FILENAMEis referenced. Otherwise, such as when used in virtual host context, the same value asREQUEST_URI. Depending on the value ofAcceptPathInfo, the server may have only used some leading components of theREQUEST_URIto map the request to a file.
Actually I find it difficult to understand the whole definition, not only the last sentence.
I use REQUEST_FILENAME and REQUEST_URI mainly between <VirtualHost *:443>.
My <VirtualHost *:443> settings:
<VirtualHost *:443>
ServerAdmin admin@exmaple.com
DocumentRoot /var/www/example.com/public_html
ServerName example.com
ServerAlias www.example.com
LogLevel alert rewrite:trace8
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
#RewriteCond %{REQUEST_URI} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule (.*) /tq_info.php?p=%{REQUSET_URI}
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/..php$
RewriteCond %{REQUEST_FILENAME} !/admin/.
RewriteRule (.*) /index.php/$1 [L]
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
REQUEST_FILENAMEdoesn't automaticallly add document root at all. For example, if I writeRewriteCond %{REQUEST_FILENAME} !-f, and the url I type iswww.example.com/hello.txt.%{REQUEST_FILENAME}would be/hello.txt, a file under root directory and apache would check whether it exists. It is not going to checkvar/www.example.com/public_html/hello.txt. It won't add the document root. So I think what you said isn't correct. Maybe I misunderstood your word? – Rick Jul 12 '20 at 09:56REQUEST_FILENAME? You could write a trivial PHP script to print both values, and then you would see the difference. – Michael Hampton Jul 12 '20 at 12:28