Reputation: 13
We have a website and a website with Arabic and English addresses. We need to redirect some URLs with a 404 status code to a 410 status code in the NGINX web service (due to SEO). We configured the NGINX web service and added Arabic and English URLs, English URLs successfully redirect to status code 410 (NGINX error page), but the redirection of Arabic URLs does not work and gives users a 404 error page The final show. My question is why redirecting Arabic URLs doesn't work, since the configuration of the two types of URLs (Arabic and English) is exactly the same.
Example URLs: https://example.com/test And https://example.com/تست
NGINX configuration file:
map $request_uri $is_retired_url {
including /etc/nginx/conf.d/redirects/410.redirects;
}
server {
if ($is_retired_url) {
return 410;
}
Contents of file 410.redirects:
/test 1;
/تست 1;
Also, I encoded Arabic URLs with https://www.urlencoder.org/, but it doesn't work.
NGINX configuration reference: https://jonathanmh.com/nginx-410-maps-and-custom-error-page/
Upvotes: 1
Views: 180
Reputation: 49702
The file 410.redirects
contains bidirectional text which initially made the question difficult to understand, but that is not the fundamental problem.
The variable $request_uri
contains the original request as received by Nginx from the browser. Although the browser will show a URL containing Arabic text, what is actually transmitted is a URL containing url-encoded characters. For example, the Arabic text in your question appears in $request_uri
as:
/%D8%AA%D8%B3%D8%AA
Nginx has another variable called $uri
which is initially set to a normalised version of $request_uri
. Part of the normalisation process is decoding url-encoded characters back to their original form.
Your existing 410.redirects
file will work if you change the map
from $request_uri
to $uri
.
For example:
map $uri $is_retired_url {
including /etc/nginx/conf.d/redirects/410.redirects;
}
Upvotes: 1