Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -1593,10 +1593,11 @@ const char *zNotFound, /* Redirect here on a 404 if not NULL */ Glob *pFileGlob, /* Deliver static files matching */ int allowRepoList /* Send repo list for "/" URL */ ){ const char *zPathInfo; + const char *zDirPathInfo; char *zPath = NULL; int idx; int i; /* Handle universal query parameters */ @@ -1607,11 +1608,21 @@ } /* If the repository has not been opened already, then find the ** repository based on the first element of PATH_INFO and open it. */ - zPathInfo = PD("PATH_INFO",""); + zDirPathInfo = zPathInfo = PD("PATH_INFO",""); + /* For the PATH_INFO that will be used to help build the final + ** g.zBaseURL and g.zTop (only), skip over the initial directory + ** portion of PATH_INFO; otherwise, it may be duplicated. + */ + if( g.zTop ){ + int nTop = strlen(g.zTop); + if ( strncmp(zDirPathInfo, g.zTop, nTop)==0 ){ + zDirPathInfo += nTop; + } + } if( !g.repositoryOpen ){ char *zRepo, *zToFree; const char *zOldScript = PD("SCRIPT_NAME", ""); char *zNewScript; int j, k; @@ -1645,12 +1656,14 @@ if( zRepo[0]=='/' && zRepo[1]=='/' ){ zRepo++; j--; } szFile = file_size(zRepo); /* this should only be set from the --baseurl option, not CGI */ if( g.zBaseURL && g.zBaseURL[0]!=0 && g.zTop && g.zTop[0]!=0 && file_isdir(g.zRepositoryName)==1 ){ - g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); - g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); + if( zPathInfo==zDirPathInfo ){ + g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); + g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); + } } } if( szFile<0 && i>0 ){ const char *zMimetype; assert( fossil_strcmp(&zRepo[j], ".fossil")==0 );