I have two copies of the website in separate directories for different languages (Spanish and English) and the directory structure is as follows
+ /var/www/website
|- es
|- en
The es
directory serves the Spanish version of the website and en
serves the English version (default language).
The URL schema would be like
# English version
https://example.com/
https://example.com/en/ -> Redirects to https://example.com/
# Spanish version
https://example.com/es/
The static files are served from the respective directories only.
Now, I have the following Apache2
configuration
<VirtualHost *:443>
# The primary domain for this host
ServerName example.com
DocumentRoot /var/www/website
<Directory /var/www/website>
Require all granted
AllowOverride all
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^$ /es/ [R]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [R]
RewriteCond %{HTTP:Accept-Language} !^en [NC]
RewriteCond %{HTTP:Accept-Language} !^es [NC]
RewriteRule ^$ /en/ [R]
</Directory>
</VirtualHost>
I'm facing a few problems with the configuration
https://example.com/es/
andhttps://example.com/en/
are working but static files are not loading and the URL for the static files looks likehttps://example.com/image.png
which has to behttps://example.com/es/image.png
(for Spanish) andhttps://example.com/en/image.png
(for English)https://example.com/en/
should be redirected tohttps://example.com/
and the English website should be served, whereas the reverse is happening.