Apache rewrite rule to serve assets based on language in path

Viewed 11

I have the following directory structure

. /var/www/html/website/
├── en-US
│   ├── assets
│   │   └── images
│   │       └── icon.png
│   │       └── image.png
│   ├── fonts
│   │   └── FontAwesome.otf
│   ├── index.html
│   ├── about/index.html
├── es
│   ├── assets
│   │   └── images
│   │       └── icon.png
│   │       └── image.png
│   ├── fonts
│   │   └── FontAwesome.otf
│   ├── index.html
│   ├── about/index.html

The website can be accessed using

https://example.com/es/      -> Spanish
https://example.com/en-US/   -> English

The assets are referred in the HTML files as

<img src="assets/images/image.png">

Using the following Apache 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-US/ [R]

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

https://example.com/es/ is serving the index.html file but statics are not serving from this directory.

I want to serve assets from the respective language directories based on the language in the URL.

0 Answers
Related