<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><base href="x-msg://2/"><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>HI Travis,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I am trying to redirect the user to the location of my website.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>For eg. The user enters <a href="http://X.X.X.X/login">http://X.X.X.X/login</a><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I want to redirect the user to <a href="http://www.mywebsite.com/login">http://www.mywebsite.com/login</a><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In the regular expression I am replacing the HOST NAME i.e. http://X.X.X.X with <a href="http://www.mywebsite.com">http://www.mywebsite.com</a>.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Therefore, I am just setting the header value to <a href="http://www.mywebsite.com/login">http://www.mywebsite.com/login</a><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>And then in the next line<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Set , obj.location to : <a href="http://www.mywebsite.com/login">http://www.mywebsite.com/login</a><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This was what I intended to accomplish.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Puneet<o:p></o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'> Travis Crowder [mailto:travis.crowder@spechal.com] <br><b>Sent:</b> Saturday, July 27, 2013 11:04 PM<br><b>To:</b> Puneet<br><b>Cc:</b> varnish-misc@varnish-cache.org<br><b>Subject:</b> Re: Stop users accessing website via IP address<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Your regular expression is malformed and you don't do any capturing or replacement in the regsub function so I am not sure what you're trying to accomplish there.<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Can you elaborate on what you're trying set this header's value to?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>-Travis Crowder<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>On Jul 27, 2013, at 9:38 PM, Puneet <<a href="mailto:puneet.arora@insticator.com">puneet.arora@insticator.com</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal><br><br><o:p></o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>HI Travis,</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks for the reply.</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I think that should work.</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Just one question.</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In sub vcl_error() should I also change the</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>set req.http.X-REDIRURL = regsub(<b>req.url</b>,"https?://[^/$]+", "</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><a href="http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5qRF&_t=tracking_anet" target=blank><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#006699;border:none windowtext 1.0pt;padding:0in;background:white;text-decoration:none'>http://mywebsite.com</span></a></span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>");</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>TO :<span class=apple-converted-space> </span></span><span style='font-size:10.0pt;font-family:Wingdings;background:white'>à</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>set req.http.X-REDIRURL = regsub(<b>req.http.host</b>,"https?://[^/$]+", "</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><a href="http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5qRF&_t=tracking_anet" target=blank><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#006699;border:none windowtext 1.0pt;padding:0in;background:white;text-decoration:none'>http://mywebsite.com</span></a></span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>");</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>?</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Because when<span class=apple-converted-space> </span><b>replace req.url with req.http.host</b>, It again stops working.</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>And<span class=apple-converted-space> </span><b>If I don’t do it</b>, the bowser gives an error<span class=apple-converted-space> </span><b>“Too many redirects”</b></span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Puneet</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><div><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>From:</span></b><span class=apple-converted-space><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'> </span></span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>Travis Crowder [mailto:travis.crowder@<a href="http://spechal.com">spechal.com</a>]<span class=apple-converted-space> </span><br><b>Sent:</b><span class=apple-converted-space> </span>Saturday, July 27, 2013 7:53 PM<br><b>To:</b><span class=apple-converted-space> </span>Puneet<br><b>Cc:</b><span class=apple-converted-space> </span><a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br><b>Subject:</b><span class=apple-converted-space> </span>Re: Stop users accessing website via IP address</span><o:p></o:p></p></div></div></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>Check against req.http.Host<o:p></o:p></p></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>In vcl_recv:<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><div><p class=MsoNormal>     if(req.http.Host ~ "8.8.8.8") {<o:p></o:p></p></div></div><div><div><p class=MsoNormal>         error 750;<o:p></o:p></p></div></div><div><div><p class=MsoNormal>     }<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>-Travis Crowder<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><div><p class=MsoNormal>On Jul 27, 2013, at 3:48 PM, Puneet <<a href="mailto:puneet.arora@insticator.com"><span style='color:purple'>puneet.arora@insticator.com</span></a>> wrote:<o:p></o:p></p></div></div><div><p class=MsoNormal><br><br><br><o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>Hi all,</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><br><span style='background:white'>I want to stop the users accessing my website via IP address.</span><br><span style='background:white'>I am using varnish as cache.</span><br><span style='background:white'>I have the following code in place but it is not working.</span><br><br><span style='background:white'>In vcl_recv() {</span><br><span style='background:white'>     if(req.url ~ "XX.XX.XXX.XXX") {</span><br><span style='background:white'>     error 750 "Moved Permanently";</span><br><span style='background:white'>  } }<span class=apple-converted-space> </span></span><br><br><span style='background:white'>And in vcl_error()</span><br><span style='background:white'>sub vcl_error {</span><br><span style='background:white'>    if (obj.status == 750) {</span><br><span style='background:white'>    set req.http.X-REDIRURL = regsub(req.url,"https?://[^/$]+", "</span></span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><a href="http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5qRF&_t=tracking_anet" target=blank><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#006699;border:none windowtext 1.0pt;padding:0in;background:white;text-decoration:none'>http://mywebsite.com</span></a></span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>");</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><br><span style='background:white'>    set obj.http.Location = req.http.X-REDIRURL;</span><br><span style='background:white'>    set obj.status = 301;</span><br><span style='background:white'>    unset req.http.X-REDIRURL;</span><br><span style='background:white'>    return(deliver);</span><br><span style='background:white'>}</span><br><br><span style='background:white'>But this does not redirect the user to the website, instead it delivers the page.</span><br><span style='background:white'>Can anyone tell what I am missing?</span></span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>Thanks</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>Puneet</span><o:p></o:p></p></div></div><div><p class=MsoNormal><span style='font-size:13.5pt;font-family:"Helvetica","sans-serif"'>_______________________________________________<br>varnish-misc mailing list<br><a href="mailto:varnish-misc@varnish-cache.org"><span style='color:#954F72'>varnish-misc@varnish-cache.org</span></a><br><a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc"><span style='color:#954F72'>https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</span></a></span><o:p></o:p></p></div></blockquote></div></div></div></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div></body></html>