You are on page 1of 13

URL Rewrite for Developers

URL Parts and Other Useful Server Variables

Scott Forsyth
weblogs.asp.net/owscott
@scottforsyth
scott@vaasnet.com
In this Module

Five Core URL Parts

Discovery

HTTP Headers
Five Core URL Parts

Discovery

HTTP Headers
Five Core URL Parts

http(s)://www.localtest.me:80/events/article.aspx?id=123
Name Example Server Variable Notes
Domain Name www.localtest.me {HTTP_HOST} IP if visited by IP
Port 80 {SERVER_PORT} 80 or 443 if not shown
Query String id=123 {QUERY_STRING}
Protocol http {HTTPS} ‘on’ or ‘off’
Match URL events/article.aspx Match URL in Never a beginning
rule slash
URL (condition) /events/article.aspx {URL} Always a beginning
slash
Path with query /events/articles.aspx?id=1 {REQUEST_URI} Always a beginning
string 23 slash. Includes query
string.
Entire URL http://...article.aspx?id=12 {CACHE_URL} Includes the port,
3 even if not shown in
browser.
http(s)://www.localtest.me:80/events/article.aspx/postpath/?id=123

Server Variable Sample Data


{URL} /events/article.aspx
Match URL events/article.aspx/postpath
/
Five Core URL Parts

Discovery

HTTP Headers
View Server Variables

<%
For Each var As String in Request.ServerVariables
Response.Write(var & ": " & Request(var) & "<br>")
Next
%>
Additional Server Variables (Page 1 of 2)
Also see: http://tinyurl.com/servervars

Server Variable Sample Data


{HTTPS} Off
{HTTP_HOST} localtest.me
{SERVER_PORT} 80
{URL} /sub/vars.aspx
Match URL Sub/vars.aspx/postpath/321
{QUERY_STRING} id=123
{REQUEST_URI} /sub/vars.aspx/postpath/321?id=123
{SERVER_PORT_SECURE} 0
{REQUEST_METHOD} GET
{SERVER_ADDR} 192.168.1.20 (public website’s IP)
{REMOTE_ADDR} 10.0.0.20 (client’s IP)
{HTTP_REFERER} Referrer URL, such as www.bing.com
{REQUEST_FILENAME} c:\inetpub\localtest.me
{SERVER_ADDR} 127.0.0.1
Additional Server Variables (Page 2 of 2)

Server Variable Sample Data


{UNENCODED_URL} Usually the same as REQUEST_URI but can differ for different character encoding or some
unique paths. It’s the URL before IIS treatments. One way to see the difference is to use a
tool such as Fiddler and visit http://localtest.me/sub/../sub/. The UNENCODED_URL
variable contains the ../sub, whereas REQUEST_URI has the cleaned-up version. Since most
browsers also clean it up, you can’t easily test this in a web browser. The usage is limited
for URL Rewrite but more common for ISAPI extensions or some PHP applications.
{CACHE_URL} http://localtest.me:80/sub/vars.aspx/postpath/321?id=123
{PATH_INFO} /sub/vars.aspx/postpath/321
{CERT_ *} Many certificate-related fields for SSL
{HTTP_ACCEPT_LANGUAGE} en-US,en;q=0.8
{HTTP_COOKIE} Cookies from the browser
{REMOTE_USER} Server01\User01
{AUTH_TYPE} Negotiate (blank for Anonymous)
{HTTP_USER_AGENT} Mozilla/5.0 …
Five Core URL Parts

Discovery

HTTP Headers

{HTTP_HOST}
{HTTP_ACCEPT_ENCODING}
{HTTP_USER_AGENT}
Three Rules when Naming HTTP Headers

 Underscore (_) symbols are converted to dashs (-)


 All letters are converted to lowercase
 The HTTP_ prefix is removed
Where Are We?

Five Core URL Parts

Discovery

HTTP Headers

You might also like