@@ -262,9 +262,11 @@ func run(ctx context.Context) error {
262
262
flag .Var (& skeys , "skey" , "the SSL key for domain" )
263
263
flag .Var (& scerts , "scert" , "the SSL cert for domain" )
264
264
265
+ var trimSlashLimit int
265
266
var noRedirectIndex , trimLastSlash bool
266
267
flag .BoolVar (& noRedirectIndex , "no-redirect-index" , false , "Whether serve with index.html without redirect." )
267
268
flag .BoolVar (& trimLastSlash , "trim-last-slash" , false , "Whether trim last slash by HTTP redirect(302)." )
269
+ flag .IntVar (& trimSlashLimit , "trim-slash-limit" , 0 , "Only trim last slash when got enough directories." )
268
270
269
271
flag .Usage = func () {
270
272
fmt .Println (fmt .Sprintf ("Usage: %v -t http -s https -d domains -r root -e cache -l lets -k ssk -c ssc -p proxy" , os .Args [0 ]))
@@ -327,7 +329,7 @@ func run(ctx context.Context) error {
327
329
if trimLastSlash {
328
330
noRedirectIndex = true
329
331
}
330
- fmt .Println (fmt .Sprintf ("Config trimLastSlash=%v, noRedirectIndex=%v" , trimLastSlash , noRedirectIndex ))
332
+ fmt .Println (fmt .Sprintf ("Config trimLastSlash=%v, trimSlashLimit=%v, noRedirectIndex=%v" , trimLastSlash , trimSlashLimit , noRedirectIndex ))
331
333
332
334
var proxyUrls []* url.URL
333
335
proxies := make (map [string ]* url.URL )
@@ -387,8 +389,10 @@ func run(ctx context.Context) error {
387
389
if r .URL .RawQuery != "" {
388
390
u += "?" + r .URL .RawQuery
389
391
}
390
- http .Redirect (w , r , u , http .StatusFound )
391
- return
392
+ if strings .Count (u , "/" ) >= trimSlashLimit {
393
+ http .Redirect (w , r , u , http .StatusFound )
394
+ return
395
+ }
392
396
}
393
397
394
398
// Append the index.html path if access a directory.
0 commit comments