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_FILENAME
is 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_URI
to 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>