forked from mixxxdj/manual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htaccess
46 lines (38 loc) · 1.76 KB
/
htaccess
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# This htaccess file is used to do language redirects based on the first
# language in the Accept-Language HTTP header.
#
# Fallback order: lang-region -> lang -> en
RewriteEngine On
# Since the redirects in this file vary based on the Accept-Language header, we
# set the Vary header so that reverse proxy caches (e.g. Cloudflare) know how to
# key the cache.
<IfModule mod_headers.c>
Header set Vary "Accept-Language"
</IfModule>
# Record the base URI in ENV::BASE.
# https://stackoverflow.com/questions/21062290/set-rewritebase-to-the-current-folder-path-dynamically
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
# First, append Accept-Language to the URL.
RewriteRule ^$ %{REQUEST_URI}%{HTTP:Accept-Language} [L,R=301]
# Then, hackily extract the first preferrered language by stripping everything
# from a comma or semicolon onward.
RewriteCond %{REQUEST_URI} [,;]
RewriteRule ^([^,;]+).*$ %{ENV:BASE}$1 [L,R=301]
# Rewrite any HTML/JS/CSS/PDF legacy links from http://mixxx.org/manual/2.1/* to
# http://mixxx.org/manual/2.1/en/*
RewriteCond $1 \.(html|js|css|pdf|gif|png|jpg|svg)$
# Ignore any URL with a slash in it (assuming it is already a language-specific URL).
RewriteCond $1 !^[^/]+/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ %{ENV:BASE}en/$1 [L,R=301]
# If the requested path is not a directory and has a dash then try stripping
# everything after the dash (e.g. fr-CA -> fr).
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} [-]
RewriteRule ^([^-/]+)[^/]+$ %{ENV:BASE}$1 [L,R=301]
# If the requested path is not a directory then redirect to en (e.g. xy -> en).
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]+$ %{ENV:BASE}en/ [L,R=301]