15-Mar-2022 12:34 - edited 15-Mar-2022 12:35
I am trying to use the following code to convert html links to those with PDFs as the target. The issue I have is with concatenation and the correct syntax. The code below gives a trailing close bracket on the URL:
HTTP::respond 301 Location [concat "https://[HTTP::host]/archive"[string map -nocase {".html" ".pdf"} [HTTP::uri]]]
Solved! Go to Solution.
15-Mar-2022 22:05
You don't really need to use the concat command here, you can just order your strings inline like this:
HTTP::respond 301 Location "https://[HTTP::host]/archive/[string map -nocase {.html .pdf} [HTTP::uri]]"
You can also test this Tcl syntax with placeholders in the tcl shell:
% set host www.example.com
www.example.com
% set uri1 matching-uri.html
matching-uri.html
% set uri2 unmatching-uri.htm
unmatching-uri.htm
% set uri3 unmatching-uri.pdf
unmatching-uri.pdf
% puts “https://$host/archive/[string map -nocase {.html .pdf} $uri1]”
“https://www.example.com/archive/matching-uri.pdf”
% puts “https://$host/archive/[string map -nocase {.html .pdf} $uri2]”
“https://www.example.com/archive/unmatching-uri.htm”
% puts “https://$host/archive/[string map -nocase {.html .pdf} $uri3]”
“https://www.example.com/archive/unmatching-uri.pdf”
15-Mar-2022 22:05
You don't really need to use the concat command here, you can just order your strings inline like this:
HTTP::respond 301 Location "https://[HTTP::host]/archive/[string map -nocase {.html .pdf} [HTTP::uri]]"
You can also test this Tcl syntax with placeholders in the tcl shell:
% set host www.example.com
www.example.com
% set uri1 matching-uri.html
matching-uri.html
% set uri2 unmatching-uri.htm
unmatching-uri.htm
% set uri3 unmatching-uri.pdf
unmatching-uri.pdf
% puts “https://$host/archive/[string map -nocase {.html .pdf} $uri1]”
“https://www.example.com/archive/matching-uri.pdf”
% puts “https://$host/archive/[string map -nocase {.html .pdf} $uri2]”
“https://www.example.com/archive/unmatching-uri.htm”
% puts “https://$host/archive/[string map -nocase {.html .pdf} $uri3]”
“https://www.example.com/archive/unmatching-uri.pdf”