<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)"><style><!--
/* Font Definitions */
@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:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@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="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white'>Hi all,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'><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><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 style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white'>");</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'><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?<o:p></o:p></span></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white'>Thanks<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white'>Puneet</span><o:p></o:p></p></div></body></html>