Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll just share my solution, which expands Richard's code into a complete solution.</p> <p>If URL contains upper case letters, we redirect user to the correct URL, instead of simply normalizing the URL before entering the cache machinery. This prevents search engines from indexing mixed case URLs separately from lower-case.</p> <pre><code># Define a function that converts a string to lower-case in-place. # http://stackoverflow.com/questions/6857445 C{ #include &lt;ctype.h&gt; static void strtolower(char *c) { for (; *c; c++) { if (isupper(*c)) { *c = tolower(*c); } } } }C sub vcl_recv { if (req.http.host ~ "[A-Z]" || req.url ~ "[A-Z]") { # Convert host and path to lowercase in-place. C{ strtolower(VRT_GetHdr(sp, HDR_REQ, "\005host:")); strtolower((char *)VRT_r_req_url(sp)); }C # Use req.http.location as a scratch register; any header will do. set req.http.location = "http://" req.http.host req.url; error 999 req.http.location; } # Fall-through to default } sub vcl_error { # Check for redirects - redirects are performed using: error 999 "http://target-url/" # Thus we piggyback the redirect target in the error response variable. if (obj.status == 999) { set obj.http.location = obj.response; set obj.status = 301; set obj.response = "Moved permanently"; return(deliver); } # Fall-through to default } </code></pre> <p>There's an ugly cast from <code>const char *</code> to <code>char *</code> when converting <code>req.url</code> to lower-case... basically, we're modifying the string in-place despite Varnish telling us not to. It seems to work. :-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload