Book Now
Advanced Technical SEO

Redirecting Spaces or Special Characters

¿Sabías que los caracteres especiales pueden arruinar tus redirecciones? Aquí te explico cómo implementarlas de una forma correcta.

Redirecting Spaces or Special Characters
Author:
Carlos Sánchez
Topics:
servers
Publication Date:
2024-08-28

Last Review:
2024-08-28

There are certain doubts that can arise when it comes to making server-side redirects that can present a real headache.
We need to bear in mind that if our URL contains a question mark "?", it is a parameter. Therefore, this type of redirect would be a query string redirect, and due to its characteristics, it is done differently.

Redirecting special characters

When we see a URL with special characters such as accented letters or letters from other alphabets, when copying the URL for redirecting, it ends up showing a code like this:

UTF-8 Bytes Code from Grupohost

For example, if we go to the URL https://example.com/acentuación and copy the URL again, this other URL will appear: https://example.com/acentuaci%C3%B3n

This is due to the character encoding itself. However, although it may seem counterintuitive, the correct solution via a RedirectMatch would be to use the URL with the characters as they are, not the UTF8 encoding. And the same would happen with characters in other alphabets, as I show in the video.

Therefore, the correct way to do the redirect would be this:

correct implementation of redirects with special characters

And not this:

redirect accents htaccess

Redirecting all accents from the server

Now, there are also ways to automate the process. For example, this would be a way to make all the "á" in the URLs change to "a".
</IfModule>
RewriteEngine On
RewriteRule ^([^á]*)á([^á]*á.*) $1a$2 [N]
RewriteRule ^([^á]*)á([^á]*)$ /$1a$2 [L,R=301]
</IfModule>

You cannot do a Replace like with JavaScript from the server, and as there may be several "á" in the same URL, a "plural" Replace is done first and then another for the last one to be replaced. In the Master's in Technical SEO, students will have a cheatsheet for implementation with all the accents. In any case, we would need to have all the files with their names replaced. Although there are ways to do this quickly, for example with the tool Bulk Rename Utility.

Why doesn't it work with white spaces?

The %20, which is the code that leaves a space in the ASCII encoding for URL ASCII encoding for URL, can mainly be produced by multimedia content with a white space.

In this example from a government website, we can see this PDF that was uploaded with a white space and generates that "%20":

URL with white spaces

To redirect a URL with these characteristics, we will need to use Regex and replace the spaces with a "\s". Fortunately, to make it easier, I have automated that process in the .htaccess redirect tool and the nginx tool:

white spaces htaccess

Bibliography

If you like this article, you would help me a lot by sharing my content:
Interested in Advanced SEO Training?

I currently offer advanced SEO training in Spanish. Would you like me to create an English version? Let me know!

Tell me you're interested
You might be interested in other articles:
SEO Articles

If you liked this post, you can always show your appreciation by liking this LinkedIn post about this same article.

Usamos cookies para asegurar que te damos la mejor experiencia en nuestra web. Aquí tienes nuestra política de privacidad.