4 IF_FEATURE_HTTPD_BASIC_AUTH(" [-r REALM]") \
6 "or httpd -d/-e" IF_FEATURE_HTTPD_AUTH_MD5("/-m") " STRING"
7 + " [-R <path> [-H <host>]]"
8 #define httpd_full_usage "\n\n" \
9 "Listen for incoming HTTP requests\n" \
12 "\n -m STRING MD5 crypt STRING") \
13 "\n -e STRING HTML encode STRING" \
14 "\n -d STRING URL decode STRING" \
15 + "\n -R PATH Redirect target path" \
16 + "\n -H HOST Redirect target host" \
18 #define hwclock_trivial_usage \
19 IF_FEATURE_HWCLOCK_LONG_OPTIONS( \
20 --- a/networking/httpd.c
21 +++ b/networking/httpd.c
22 @@ -250,6 +250,8 @@ struct globals {
24 const char *found_mime_type;
25 const char *found_moved_temporarily;
26 + const char *redirect_path;
27 + const char *redirect_host;
28 Htaccess_IP *ip_a_d; /* config allow/deny lines */
30 IF_FEATURE_HTTPD_BASIC_AUTH(const char *g_realm;)
31 @@ -296,6 +298,8 @@ struct globals {
32 #define index_page (G.index_page )
33 #define found_mime_type (G.found_mime_type )
34 #define found_moved_temporarily (G.found_moved_temporarily)
35 +#define redirect_path (G.redirect_path )
36 +#define redirect_host (G.redirect_host )
37 #define last_mod (G.last_mod )
38 #define ip_a_d (G.ip_a_d )
39 #define g_realm (G.g_realm )
40 @@ -997,8 +1001,11 @@ static void send_headers(int responseNum
43 if (responseNum == HTTP_MOVED_TEMPORARILY) {
44 - len += sprintf(iobuf + len, "Location: %s/%s%s\r\n",
45 + len += sprintf(iobuf + len, "Location: %s%s%s%s%s%s\r\n",
46 + (redirect_host ? "http://" : ""),
47 + (redirect_host ? redirect_host : ""),
48 found_moved_temporarily,
49 + (redirect_host ? "" : "/"),
51 (g_query ? g_query : ""));
53 @@ -1941,8 +1948,12 @@ static void handle_incoming_and_exit(con
55 *++urlp = '\0'; /* terminate after last character */
57 + /* redirect active */
58 + if (redirect_path && (strncmp(urlcopy, redirect_path, strlen(redirect_path)) != 0))
59 + found_moved_temporarily = redirect_path;
61 /* If URL is a directory, add '/' */
62 - if (urlp[-1] != '/') {
63 + if (!redirect_path && (urlp[-1] != '/')) {
64 if (is_directory(urlcopy + 1, 1, NULL)) {
65 found_moved_temporarily = urlcopy;
67 @@ -2283,7 +2294,9 @@ static void sighup_handler(int sig UNUSE
71 - c_opt_config_file = 0,
72 + R_opt_redirect_path = 0,
73 + H_opt_redirect_host,
77 IF_FEATURE_HTTPD_ENCODE_URL_STR(e_opt_encode_url,)
78 @@ -2332,12 +2345,13 @@ int httpd_main(int argc UNUSED_PARAM, ch
79 /* We do not "absolutize" path given by -h (home) opt.
80 * If user gives relative path in -h,
81 * $SCRIPT_FILENAME will not be set. */
82 - opt = getopt32(argv, "c:d:h:"
83 + opt = getopt32(argv, "R:H:c:d:h:"
84 IF_FEATURE_HTTPD_ENCODE_URL_STR("e:")
85 IF_FEATURE_HTTPD_BASIC_AUTH("r:")
86 IF_FEATURE_HTTPD_AUTH_MD5("m:")
87 IF_FEATURE_HTTPD_SETUID("u:")
89 + &redirect_path, &redirect_host,
90 &opt_c_configFile, &url_for_decode, &home_httpd
91 IF_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
92 IF_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)