Fossil SCM

Change unconditional CGI redirects to be 301 Moved Permanently.

drh 2025-04-04 10:58 trunk
Commit 33c1cfde9c6e8d5f4b3b91720264c75b58ec9059e8de5f2ed167743412fda897
2 files changed +3 +20 -4
+3
--- src/cgi.c
+++ src/cgi.c
@@ -637,10 +637,13 @@
637637
cgi_set_status(iStat, zStat);
638638
free(zLocation);
639639
cgi_reply();
640640
fossil_exit(0);
641641
}
642
+NORETURN void cgi_redirect_perm(const char *zURL){
643
+ cgi_redirect_with_status(zURL, 301, "Moved Permanently");
644
+}
642645
NORETURN void cgi_redirect(const char *zURL){
643646
cgi_redirect_with_status(zURL, 302, "Moved Temporarily");
644647
}
645648
NORETURN void cgi_redirect_with_method(const char *zURL){
646649
cgi_redirect_with_status(zURL, 307, "Temporary Redirect");
647650
--- src/cgi.c
+++ src/cgi.c
@@ -637,10 +637,13 @@
637 cgi_set_status(iStat, zStat);
638 free(zLocation);
639 cgi_reply();
640 fossil_exit(0);
641 }
 
 
 
642 NORETURN void cgi_redirect(const char *zURL){
643 cgi_redirect_with_status(zURL, 302, "Moved Temporarily");
644 }
645 NORETURN void cgi_redirect_with_method(const char *zURL){
646 cgi_redirect_with_status(zURL, 307, "Temporary Redirect");
647
--- src/cgi.c
+++ src/cgi.c
@@ -637,10 +637,13 @@
637 cgi_set_status(iStat, zStat);
638 free(zLocation);
639 cgi_reply();
640 fossil_exit(0);
641 }
642 NORETURN void cgi_redirect_perm(const char *zURL){
643 cgi_redirect_with_status(zURL, 301, "Moved Permanently");
644 }
645 NORETURN void cgi_redirect(const char *zURL){
646 cgi_redirect_with_status(zURL, 302, "Moved Temporarily");
647 }
648 NORETURN void cgi_redirect_with_method(const char *zURL){
649 cgi_redirect_with_status(zURL, 307, "Temporary Redirect");
650
+20 -4
--- src/main.c
+++ src/main.c
@@ -2053,11 +2053,12 @@
20532053
*/
20542054
set_base_url(0);
20552055
if( fossil_redirect_to_https_if_needed(2) ) return;
20562056
if( zPathInfo==0 || zPathInfo[0]==0
20572057
|| (zPathInfo[0]=='/' && zPathInfo[1]==0) ){
2058
- /* Second special case: If the PATH_INFO is blank, issue a redirect:
2058
+ /* Second special case: If the PATH_INFO is blank, issue a
2059
+ ** temporary 302 redirect:
20592060
** (1) to "/ckout" if g.useLocalauth and g.localOpen are both set.
20602061
** (2) to the home page identified by the "index-page" setting
20612062
** in the repository CONFIG table
20622063
** (3) to "/index" if there no "index-page" setting in CONFIG
20632064
*/
@@ -2267,10 +2268,21 @@
22672268
**
22682269
** #!/usr/bin/fossil
22692270
** redirect: * https://fossil-scm.org/home
22702271
**
22712272
** Thus requests to the .com website redirect to the .org website.
2273
+** This form uses a 301 Permanent redirect.
2274
+**
2275
+** On a "*" redirect, the PATH_INFO and QUERY_STRING of the query
2276
+** that provoked the redirect are appended to the target. So, for
2277
+** example, if the input URL for the redirect above were
2278
+** "http://www.fossil.com/index.html/timeline?c=20250404", then
2279
+** the redirect would be to:
2280
+**
2281
+** https://fossil-scm.org/home/timeline?c=20250404
2282
+** ^^^^^^^^^^^^^^^^^^^^
2283
+** Copied from input URL
22722284
*/
22732285
static void redirect_web_page(int nRedirect, char **azRedirect){
22742286
int i; /* Loop counter */
22752287
const char *zNotFound = 0; /* Not found URL */
22762288
const char *zName = P("name");
@@ -2297,21 +2309,22 @@
22972309
}
22982310
if( zNotFound ){
22992311
Blob to;
23002312
const char *z;
23012313
if( strstr(zNotFound, "%s") ){
2302
- cgi_redirectf(zNotFound /*works-like:"%s"*/, zName);
2314
+ char *zTarget = mprintf(zNotFound /*works-like:"%s"*/, zName);
2315
+ cgi_redirect_perm(zTarget);
23032316
}
23042317
if( strchr(zNotFound, '?') ){
2305
- cgi_redirect(zNotFound);
2318
+ cgi_redirect_perm(zNotFound);
23062319
}
23072320
blob_init(&to, zNotFound, -1);
23082321
z = P("PATH_INFO");
23092322
if( z && z[0]=='/' ) blob_append(&to, z, -1);
23102323
z = P("QUERY_STRING");
23112324
if( z && z[0]!=0 ) blob_appendf(&to, "?%s", z);
2312
- cgi_redirect(blob_str(&to));
2325
+ cgi_redirect_perm(blob_str(&to));
23132326
}else{
23142327
@ <html>
23152328
@ <head><title>No Such Object</title></head>
23162329
@ <body>
23172330
@ <p>No such object: <b>%h(zName)</b></p>
@@ -2394,10 +2407,13 @@
23942407
** REPO for a check-in or ticket that matches the
23952408
** value of "name", then redirect to URL. There
23962409
** can be multiple "redirect:" lines that are
23972410
** processed in order. If the REPO is "*", then
23982411
** an unconditional redirect to URL is taken.
2412
+** When "*" is used a 301 permanent redirect is
2413
+** issued and the tail and query string from the
2414
+** original query are appeneded onto URL.
23992415
**
24002416
** jsmode: VALUE Specifies the delivery mode for JavaScript
24012417
** files. See the help text for the --jsmode
24022418
** flag of the http command.
24032419
**
24042420
--- src/main.c
+++ src/main.c
@@ -2053,11 +2053,12 @@
2053 */
2054 set_base_url(0);
2055 if( fossil_redirect_to_https_if_needed(2) ) return;
2056 if( zPathInfo==0 || zPathInfo[0]==0
2057 || (zPathInfo[0]=='/' && zPathInfo[1]==0) ){
2058 /* Second special case: If the PATH_INFO is blank, issue a redirect:
 
2059 ** (1) to "/ckout" if g.useLocalauth and g.localOpen are both set.
2060 ** (2) to the home page identified by the "index-page" setting
2061 ** in the repository CONFIG table
2062 ** (3) to "/index" if there no "index-page" setting in CONFIG
2063 */
@@ -2267,10 +2268,21 @@
2267 **
2268 ** #!/usr/bin/fossil
2269 ** redirect: * https://fossil-scm.org/home
2270 **
2271 ** Thus requests to the .com website redirect to the .org website.
 
 
 
 
 
 
 
 
 
 
 
2272 */
2273 static void redirect_web_page(int nRedirect, char **azRedirect){
2274 int i; /* Loop counter */
2275 const char *zNotFound = 0; /* Not found URL */
2276 const char *zName = P("name");
@@ -2297,21 +2309,22 @@
2297 }
2298 if( zNotFound ){
2299 Blob to;
2300 const char *z;
2301 if( strstr(zNotFound, "%s") ){
2302 cgi_redirectf(zNotFound /*works-like:"%s"*/, zName);
 
2303 }
2304 if( strchr(zNotFound, '?') ){
2305 cgi_redirect(zNotFound);
2306 }
2307 blob_init(&to, zNotFound, -1);
2308 z = P("PATH_INFO");
2309 if( z && z[0]=='/' ) blob_append(&to, z, -1);
2310 z = P("QUERY_STRING");
2311 if( z && z[0]!=0 ) blob_appendf(&to, "?%s", z);
2312 cgi_redirect(blob_str(&to));
2313 }else{
2314 @ <html>
2315 @ <head><title>No Such Object</title></head>
2316 @ <body>
2317 @ <p>No such object: <b>%h(zName)</b></p>
@@ -2394,10 +2407,13 @@
2394 ** REPO for a check-in or ticket that matches the
2395 ** value of "name", then redirect to URL. There
2396 ** can be multiple "redirect:" lines that are
2397 ** processed in order. If the REPO is "*", then
2398 ** an unconditional redirect to URL is taken.
 
 
 
2399 **
2400 ** jsmode: VALUE Specifies the delivery mode for JavaScript
2401 ** files. See the help text for the --jsmode
2402 ** flag of the http command.
2403 **
2404
--- src/main.c
+++ src/main.c
@@ -2053,11 +2053,12 @@
2053 */
2054 set_base_url(0);
2055 if( fossil_redirect_to_https_if_needed(2) ) return;
2056 if( zPathInfo==0 || zPathInfo[0]==0
2057 || (zPathInfo[0]=='/' && zPathInfo[1]==0) ){
2058 /* Second special case: If the PATH_INFO is blank, issue a
2059 ** temporary 302 redirect:
2060 ** (1) to "/ckout" if g.useLocalauth and g.localOpen are both set.
2061 ** (2) to the home page identified by the "index-page" setting
2062 ** in the repository CONFIG table
2063 ** (3) to "/index" if there no "index-page" setting in CONFIG
2064 */
@@ -2267,10 +2268,21 @@
2268 **
2269 ** #!/usr/bin/fossil
2270 ** redirect: * https://fossil-scm.org/home
2271 **
2272 ** Thus requests to the .com website redirect to the .org website.
2273 ** This form uses a 301 Permanent redirect.
2274 **
2275 ** On a "*" redirect, the PATH_INFO and QUERY_STRING of the query
2276 ** that provoked the redirect are appended to the target. So, for
2277 ** example, if the input URL for the redirect above were
2278 ** "http://www.fossil.com/index.html/timeline?c=20250404", then
2279 ** the redirect would be to:
2280 **
2281 ** https://fossil-scm.org/home/timeline?c=20250404
2282 ** ^^^^^^^^^^^^^^^^^^^^
2283 ** Copied from input URL
2284 */
2285 static void redirect_web_page(int nRedirect, char **azRedirect){
2286 int i; /* Loop counter */
2287 const char *zNotFound = 0; /* Not found URL */
2288 const char *zName = P("name");
@@ -2297,21 +2309,22 @@
2309 }
2310 if( zNotFound ){
2311 Blob to;
2312 const char *z;
2313 if( strstr(zNotFound, "%s") ){
2314 char *zTarget = mprintf(zNotFound /*works-like:"%s"*/, zName);
2315 cgi_redirect_perm(zTarget);
2316 }
2317 if( strchr(zNotFound, '?') ){
2318 cgi_redirect_perm(zNotFound);
2319 }
2320 blob_init(&to, zNotFound, -1);
2321 z = P("PATH_INFO");
2322 if( z && z[0]=='/' ) blob_append(&to, z, -1);
2323 z = P("QUERY_STRING");
2324 if( z && z[0]!=0 ) blob_appendf(&to, "?%s", z);
2325 cgi_redirect_perm(blob_str(&to));
2326 }else{
2327 @ <html>
2328 @ <head><title>No Such Object</title></head>
2329 @ <body>
2330 @ <p>No such object: <b>%h(zName)</b></p>
@@ -2394,10 +2407,13 @@
2407 ** REPO for a check-in or ticket that matches the
2408 ** value of "name", then redirect to URL. There
2409 ** can be multiple "redirect:" lines that are
2410 ** processed in order. If the REPO is "*", then
2411 ** an unconditional redirect to URL is taken.
2412 ** When "*" is used a 301 permanent redirect is
2413 ** issued and the tail and query string from the
2414 ** original query are appeneded onto URL.
2415 **
2416 ** jsmode: VALUE Specifies the delivery mode for JavaScript
2417 ** files. See the help text for the --jsmode
2418 ** flag of the http command.
2419 **
2420

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button