for directing users to a non-secure page for instance. It has no effect
with a location-type redirect.
+ - "append-slash"
+ This keyword may be used in conjunction with "drop-query" to redirect
+ users who use a URL not ending with a '/' to the same one with the '/'.
+ It can be useful to ensure that search engines will only see one URL.
+ For this, a return code 301 is preferred.
+
- "set-cookie NAME[=value]"
A "Set-Cookie" header will be added with NAME (and optionally "=value")
to the response. This is sometimes used to indicate that a user has
redirect location http://mysite.com/ if !login_page secure
redirect location / clear-cookie USERID= if logout
+ Example: send redirects for request for articles without a '/'.
+ acl missing_slash path_reg ^/article/[^/]*$
+ redirect code 301 prefix / drop-query append-slash if missing_slash
+
See section 7 about ACL usage.
enum {
REDIRECT_FLAG_NONE = 0,
REDIRECT_FLAG_DROP_QS = 1, /* drop query string */
+ REDIRECT_FLAG_APPEND_SLASH = 2, /* append a slash if missing at the end */
};
/* Redirect types (location, prefix, extended ) */
else if (!strcmp(args[cur_arg],"drop-query")) {
flags |= REDIRECT_FLAG_DROP_QS;
}
+ else if (!strcmp(args[cur_arg],"append-slash")) {
+ flags |= REDIRECT_FLAG_APPEND_SLASH;
+ }
else if (!strcmp(args[cur_arg], "if")) {
pol = ACL_COND_IF;
cur_arg++;
break;
}
else {
- Alert("parsing [%s:%d] : '%s' expects 'code', 'prefix', 'location', 'set-cookie', 'clear-cookie' or 'drop-query' (was '%s').\n",
+ Alert("parsing [%s:%d] : '%s' expects 'code', 'prefix', 'location', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was '%s').\n",
file, linenum, args[0], args[cur_arg]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
/* add path */
memcpy(rdr.str + rdr.len, path, pathlen);
rdr.len += pathlen;
+
+ /* append a slash at the end of the location is needed and missing */
+ if (rdr.len && rdr.str[rdr.len - 1] != '/' &&
+ (rule->flags & REDIRECT_FLAG_APPEND_SLASH)) {
+ if (rdr.len > rdr.size - 5)
+ goto return_bad_req;
+ rdr.str[rdr.len] = '/';
+ rdr.len++;
+ }
+
break;
}
case REDIRECT_TYPE_LOCATION: