Automatic redirection is not working for the deployed internalized Agnular app

Discussão em 'Angular' iniciado por Ярослав Терещук, Setembro 15, 2025.

  1. I'm working on the site internalization using Angular, i18n, and Apache2.

    Steps I made

    I made site translation using an .xlf file for the uk locale. en locale was set as the source locale.

    I adjusted the build configuration to get such output build paths:

    • / - en version of the site;
    • /uk/ - localized version of the site for uk locale.

    If you run it locally via a local server, you will get localized versions of the site if you change the URL as shown above.

    I deployed the adjusted builds to my Ubuntu VPS, and it works if you manually navigate to the respective paths in the browser.

    The issue

    I want to implement automatic redirection based on users' language as shown in the Angular documentation: https://v15.angular.io/guide/i18n-common-deploy

    In the example, the redirection is made based on the HTTP request header Accept-Language.

    Despite my changes to the Apache configuration files, the redirection is not performed.

    How did I adjust the Apache configuration

    In my VPS, I navigated to the path /etc/apache2/sites-available, and adjusted the Apache configuration file for my https configuration my-site.com-le-ssl.conf (here and further I will replace my domain with my-site.com and IPs to 0.0.0.0):

    <IfModule mod_ssl.c>
    <VirtualHost *:443>
    ServerAdmin webmaster@localhost
    ServerName my-site.com
    ServerAlias www.my-site.com
    DocumentRoot /var/www/my-site.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/var/www/my-site.com">
    RewriteEngine on
    RewriteBase /
    RewriteRule ^../index\.html$ - [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (..) $1/index.html [L]

    RewriteCond %{HTTP:Accept-Language} ^uk [NC]
    RewriteRule ^$ /uk/ [R]

    RewriteCond %{HTTP:Accept-Language} ^en-US [NC]
    RewriteRule ^$ / [R]

    RewriteCond %{HTTP:Accept-Language} !^uk [NC]
    RewriteCond %{HTTP:Accept-Language} !^en-US [NC]
    RewriteRule ^$ / [R]
    </Directory>

    <Location /api>
    ProxyPass http://0.0.0.0:3000/api
    ProxyPassReverse http://0.0.0.0:3000/api
    </Location>

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/special-notes.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/special-notes.com/privkey.pem
    </VirtualHost>
    </IfModule>


    I am new to server administration and Apache itself, so I may not know some things that can be treated as basics.

    Thank you in advance.

    Continue reading...

Compartilhe esta Página