Slashes in URL Variables

I installed a coldfusion application for dynamic URLs on a page like

www.musicExplained/index.cfm/artist/:VariableName 

However, my variable names sometimes contain slashes, for example

 www.musicExplained/index.cfm/artist/GZA/Genius 

This causes a problem because my application assumes that the slash in the variable name is another section of the website, artist albums. Thus, the URL will fail.

I wonder if it's all the same to prevent this from happening? Do I need to use a function that replaces the slashes in variable names with another character?

+90
url escaping
Jun 07 2018-10-10T00-06-07
source share
3 answers

You need to escape the slash like %2F .

+148
Jun 07 2018-10-10T00-06-07
source share

You can easily replace the forward slashes / with something like an underscore _ , like Wikipedia for spaces. Replacing special characters with underscores, etc. It is a common practice.

+17
Jun 07 2018-10-10T00-06-07
source share

You need to avoid these steps, but don't just replace it with %2F manually. You can use URLEncoder for this.

Eg URLEncoder.encode(url, "UTF-8")

Then you can say

 yourUrl = "www.musicExplained/index.cfm/artist/" + URLEncoder.encode(VariableName, "UTF-8") 
+7
Oct 28 '16 at 10:38
source share



All Articles