What are the .htaccess elements REQUEST_FILENAME and THE_REQUEST?

情到浓时终转凉″ 提交于 2021-02-18 20:09:19

问题


What is returned by %{REQUEST_FILENAME} and %{THE_REQUEST}?

I was just checking over our .htaccess file and it dawned on me, I have very little knowledge of this. The code below uses both. It works I just want understand it.

#remove / at the end of URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/$ /$1 [L,R=301]

#remove /index.php at the end of URL
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L] 

Cheers, Mark


回答1:


Thanks to Ahmed for the link.
As a quick point of reference to anyone too lazy to click on it here's the bit I was after...

THE_REQUEST The full HTTP request line sent by the browser to the server (e.g., "GET /index.html HTTP/1.1"). This does not include any additional headers sent by the browser. This value has not been unescaped (decoded), unlike most other variables below.

REQUEST_URI The path component of the requested URI, such as "/index.html". This notably excludes the query string which is available as as its own variable named QUERY_STRING.

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 as REQUEST_URI. Depending on the value of AcceptPathInfo, the server may have only used some leading components of the REQUEST_URI to map the request to a file.



来源:https://stackoverflow.com/questions/17211802/what-are-the-htaccess-elements-request-filename-and-the-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!