Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Assistance with Concatenation

Walter_WorkAcct
Altostratus
Altostratus

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]]]

 

1 ACCEPTED SOLUTION

JRahm
Community Manager
Community Manager

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”

 

View solution in original post

1 REPLY 1

JRahm
Community Manager
Community Manager

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”