1 --- a/networking/httpd.c
2 +++ b/networking/httpd.c
4 //usage: IF_FEATURE_HTTPD_BASIC_AUTH(" [-r REALM]")
5 //usage: " [-h HOME]\n"
6 //usage: "or httpd -d/-e" IF_FEATURE_HTTPD_AUTH_MD5("/-m") " STRING"
7 +//usage: " [-R <path> [-H <host>]]"
8 //usage:#define httpd_full_usage "\n\n"
9 //usage: "Listen for incoming HTTP requests\n"
10 //usage: "\n -i Inetd mode"
12 //usage: "\n -m STRING MD5 crypt STRING")
13 //usage: "\n -e STRING HTML encode STRING"
14 //usage: "\n -d STRING URL decode STRING"
15 +//usage: "\n -R PATH Redirect target path"
16 +//usage: "\n -H HOST Redirect target host"
19 #if ENABLE_FEATURE_HTTPD_USE_SENDFILE
20 @@ -272,6 +275,8 @@ struct globals {
22 const char *found_mime_type;
23 const char *found_moved_temporarily;
24 + const char *redirect_path;
25 + const char *redirect_host;
26 Htaccess_IP *ip_a_d; /* config allow/deny lines */
28 IF_FEATURE_HTTPD_BASIC_AUTH(const char *g_realm;)
29 @@ -322,6 +327,8 @@ struct globals {
30 #define index_page (G.index_page )
31 #define found_mime_type (G.found_mime_type )
32 #define found_moved_temporarily (G.found_moved_temporarily)
33 +#define redirect_path (G.redirect_path )
34 +#define redirect_host (G.redirect_host )
35 #define last_mod (G.last_mod )
36 #define ip_a_d (G.ip_a_d )
37 #define g_realm (G.g_realm )
38 @@ -1028,8 +1035,11 @@ static void send_headers(int responseNum
41 if (responseNum == HTTP_MOVED_TEMPORARILY) {
42 - len += sprintf(iobuf + len, "Location: %s/%s%s\r\n",
43 + len += sprintf(iobuf + len, "Location: %s%s%s%s%s%s\r\n",
44 + (redirect_host ? "http://" : ""),
45 + (redirect_host ? redirect_host : ""),
46 found_moved_temporarily,
47 + (redirect_host ? "" : "/"),
49 (g_query ? g_query : ""));
51 @@ -1997,8 +2007,12 @@ static void handle_incoming_and_exit(con
53 *++urlp = '\0'; /* terminate after last character */
55 + /* redirect active */
56 + if (redirect_path && (strncmp(urlcopy, redirect_path, strlen(redirect_path)) != 0))
57 + found_moved_temporarily = redirect_path;
59 /* If URL is a directory, add '/' */
60 - if (urlp[-1] != '/') {
61 + if (!redirect_path && (urlp[-1] != '/')) {
62 if (is_directory(urlcopy + 1, 1, NULL)) {
63 found_moved_temporarily = urlcopy;
65 @@ -2355,7 +2369,9 @@ static void sighup_handler(int sig UNUSE
69 - c_opt_config_file = 0,
70 + R_opt_redirect_path = 0,
71 + H_opt_redirect_host,
75 IF_FEATURE_HTTPD_ENCODE_URL_STR(e_opt_encode_url,)
76 @@ -2404,12 +2420,13 @@ int httpd_main(int argc UNUSED_PARAM, ch
77 /* We do not "absolutize" path given by -h (home) opt.
78 * If user gives relative path in -h,
79 * $SCRIPT_FILENAME will not be set. */
80 - opt = getopt32(argv, "c:d:h:"
81 + opt = getopt32(argv, "R:H:c:d:h:"
82 IF_FEATURE_HTTPD_ENCODE_URL_STR("e:")
83 IF_FEATURE_HTTPD_BASIC_AUTH("r:")
84 IF_FEATURE_HTTPD_AUTH_MD5("m:")
85 IF_FEATURE_HTTPD_SETUID("u:")
87 + &redirect_path, &redirect_host,
88 &opt_c_configFile, &url_for_decode, &home_httpd
89 IF_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
90 IF_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)