I have set up my coldfusion application to have dynamic urls on the page, such as
www.musicExplained/index.cfm/artist/:VariableName
However my variable names will sometimes contain slashes, such as
www.musicExplained/index.cfm/artist/GZA/Genius
This is causing a problem, because my application presumes that the slash in the variable name represents a different section of the website, the artists albums. So the URL will fail.
I am wondering if there is anyway to prevent this from happening? Do I need to use a function that replaces slashes in the variable names with another character?
You need to escape the slashes as %2F
.
Ok, this seems like an good idea, is there any specif reason to use %2F?
This is the standard URL encoding.
IIS still intercepts this as a
/
and breaks the route. :(Apache interprets this as a / and breaks the route unless AllowEncodedSlashes directive is switched on (by default it's switched off)
You can use
encodeURIComponent
anddecodeURIComponent
for this purpose.