Serving multilingual static content through Apache for a web application

I have multilingual static content that I want to serve through Apache. Files are cache files created by the JIT application, so if they exist, they must be submitted, otherwise redirect the request to the application, which will create them in place.

I specify the language through the HTTP Accept-Languageheader, which can be hr, enbut also en-US,en;q=0.5(therefore there is no simple language to add to the file name to continue).

The urls are as follows:

In my application, I have a folder with exactly the same layout, only the language is added, for example:

/static/homepage.html.en
/static/homepage.html.hr
/static/script.js.en
/static/script.js.hr

, Accept-Language mod_negotiation :

# Alias
/static /www/app/var/cache/static
<Directory /www/app/var/cache/static>
  FileETag MTime Size
  Options MultiViews
  AddLanguage hr .hr
  AddLanguage en .en
  <IfModule mod_negotiation.c>
    LanguagePriority en hr
  </IfModule>      

  ErrorDocument 404 /index.php
</Directory>

, .

, :

  • PHP ( )
  • mod_rewrite ( Accept-Language)
  • ( )

-, ?

:

# Alias
/static /www/app/var/cache/static
<Directory /www/app/var/cache/static>
  FileETag MTime Size
  Options MultiViews
  AddLanguage hr .hr
  AddLanguage en .en
  <IfModule mod_negotiation.c>
    LanguagePriority en hr
    ForceLanguagePriority none
  </IfModule>      

  ErrorDocument 404 /index.php
  ErrorDocument 406 /index.php
</Directory>
+4
2

, ForceLanguagePriority "" " ". "", Apache 406, , 404.

+1

mod rewrite :

<Directory /www/app/var/cache/static>
  RewriteEngine On

  RewriteCond %{HTTP:Accept-Language} ^pl.*$ [NC]
  RewriteCond %{REQUEST_URI} ^.*(js|css)$ [NC]
  RewriteRule ^(.*)$ %{REQUEST_URI}.pl [L,R=302]

  RewriteCond %{HTTP:Accept-Language} ^hr.*$ [NC]
  RewriteCond %{REQUEST_URI} ^.*(js|css)$ [NC]
  RewriteRule ^(.*)$ %{REQUEST_URI}.hr [L,R=302]

  RewriteCond %{HTTP:Accept-Language} ^en.*$ [NC]
  RewriteCond %{REQUEST_URI} ^.*(js|css)$ [NC]
  RewriteRule ^(.*)$ %{REQUEST_URI}.en [L,R=302]

  # (...) do it for all languages       

  ErrorDocument 404 /index.php
</Directory>
0

All Articles