Optional background (to avoid the XY problem): I'm working on a static site which will contain URLs like
www.example.com/książka/
. The problem with those URLs is that when you share them / paste to an IM program, etc, the diacritic characters are expanded into%<hex>
and become unreadable:www.example.com/ksi%C4%85%C5%BCka/
. So I'm considering the following:
- setting the canonical URL of the page as
www.example.com/ksiazka/
("ąż" replaced with "az")- returning a temporary redirect (HTTP 302 or 307) to
www.example.com/książka/
.What won't work:
Automatic address rewriting. Reason: We're not going from "ąż" to "az", but from "az" to "ąż" or maybe "ąz", or "aż", or "áz", or one of many other possibilities. The redirects must be generated during page generation, when we know the complete list of existing pages, and so we know that "ksiazka" should redirect to "książka" and not "książką".
I need to configure 1 HTTP redirect per page. I will need one new HTTP redirect every time I upload a new article.
Editing the NGINX config requires root access and I'm deploying the site under a regular user's permissions. Under Apache you could add some directives in .htaccess
, but this is problematic for performance, and a no-go for NGINX.
Bar that, I could create an include in /etc/nginx/sites-available/mysite
to pull in contents of /home/myuser/mysite/_redirects
. So the server would read in a file controlled by a regular user. The drawback is that it would give the regular user access to all the NGINX configuration options, while I only need to set up redirects.
To work around that I could maybe write a piece of automation which reads a file uploaded by the user, containing only information required for redirects. Something like the _redirects
file in Netlify. But this feels… wrong. Too custom.
To recap:
- Static site
- HTTP 302 or HTTP 307 needed
- Frequent updates (manual editing of
/etc/nginx
not feasible) - Files uploaded as an unprivileged system user
- Not giving that user too much power over the web server
What would be a good way of doing this on NGINX?
0 Answers