1) I need to verify whether the connections are referred by my same site or by someone else. 2) I can NOT simply type the HTTP_HOST manually because the .htaccess file is meant to be handled by subversion and shared across different development environments with different HTTP_HOST values
So the goal is to find a workaround to make this condition work transparently no matter what the environment is, and keep htaccess easily handled by svn without need of manual fixes.
Thanks!
With Apache 2 you can do this:
RewriteCond %{HTTP_REFERER} ^$ [OR]
RewriteCond %{HTTP_REFERER} ^[^:/?#]+://([^/?#]+) # get authority
RewriteCond %1 ^(?:(?:[A-Za-z0-9-._~!$&'()*+,;=:]|%[0-9A-Fa-f]{2})*@)?((?:[A-Za-z0-9-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*)(?::\d+)?$ # get host name
RewriteCond %1/%{HTTP_HOST} !^([^/]+)/\1$ # compare to HTTP_HOST
RewriteRule ^ …
Note that HTTP_HOST can also be empty in case of an pre-HTTP/1.1 request.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.