0

I would like to change the %20 for "-" in the URL so that it's url friendly, I've tried everything but nothing works, not htaccess or java or php.

Here's an example of my link, not friendly at all: https://www.ugocd.com/ilustracion_galeria_clasica?id=Retrato%20digital%20Charles%20Chaplin

Here is some of my code:

<a href="ilustracion_filtro?id=<?php echo $categoria; ?>
ArtOfCode
  • 5,702
  • 5
  • 37
  • 56
  • %20 is url encoding. Spaces are not allowed in url. Here's a link on what is %20 is : https://stackoverflow.com/questions/13900835/the-origin-on-why-20-is-used-as-a-space-in-urls. – terahertz Jul 21 '19 at 15:23

1 Answers1

0

Without seeing your code, it's difficult to say what your issue really is, but I suspect what's happening here is a misunderstanding.

%20 is not a literal string, and you shouldn't try to treat it as one. %XX in URLs, where XX are two hexadecimal characters, is a URL encoded string. Values that aren't URL-safe (which is... pretty much anything other than basic US-ASCII) are encoded in this fashion so that they become URL-safe. The US-ASCII codepoint for a space is 20, so it gets encoded as %20. When you see %20 in a URL, you're actually dealing with a space, not a literal percent character, a two, and a zero.

Hence, if you try to replace this value with something else by doing this:

str_replace("%20", "", $url)

that won't work, because you're replacing the literal string not the real value. Try this instead:

str_replace(" ", "", $url)
ArtOfCode
  • 5,702
  • 5
  • 37
  • 56