Allow special characters in htaccess

0

How can I allow special characters in htaccess? I'm using:

RewriteRule ^Juegos/Xbox-One/([0-9]+)/([0-9a-zA-Z_-]+)/ single.php?ID=$1 [L]

However, letters like the ñ or accented words make the URL not work. I'm also having a problem with that sign: -

The URL example for this case is as follows: Juegos/Xbox-One/1189/Rocket-League-–-Crate-Unlock-Key-x5/

I tried to replace it in PHP using the following code:

function limpia_url ($juego) {
$titulo_limpio =  preg_replace('~[\\/:*?"<>|]~', '', $juego);
$titulo_limpio = str_replace(str_split('\/:*?"<>|'), '', $titulo_limpio);
$titulo_limpio = str_replace("-","",$titulo_limpio); //aquí debería eliminarme el carácter, pero no lo hace
$titulo_limpio = str_replace(",","-",$titulo_limpio);
$titulo_limpio = str_replace("'","",$titulo_limpio);
$titulo_limpio = str_replace(" ","-",$titulo_limpio);

return $titulo_limpio;

}

The only thing that occurs to me is that since I can not remove it, allow it in htaccess. In the case of accents, it might be better to replace them with the corresponding vowel without an accent.

    
asked by JetLagFox 31.05.2017 в 17:40
source

1 answer

1

Within the regular expression [a-z] are not the accented vowels nor the ñ.

Unfortunately not even in the group \w which is an alias of [a-zA-z_] are not the accented letters.

So you have to add these symbols individually in the regular expression unless you use the wildcard . that represents any character

The - symbol is used to define ranges so it is a special character and has to be escaped with a \

The RewriteRule you need would be something like this:

RewriteRule ^Juegos/Xbox-One/([0-9]+)/([0-9a-zA-Z_\-áéíóúÁÉÍÓÚñÑ]+)/ single.php?ID=$1 [L]
    
answered by 07.06.2017 в 11:12