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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
---
---
###############################################################################
# WARNING
###############################################################################
# Only modify this file if you know what you're doing. This file has
# the potential to make pages become PERMANENTLY UNREACHABLE. If in
# doubt, refer to these links:
#
# RewriteRule - http://httpd.apache.org/docs/current/mod/mod_rewrite.html
# RewriteRule flags - http://httpd.apache.org/docs/current/rewrite/flags.html
# .htaccess tester - http://htaccess.madewithlove.be/
#
# And remember: three-oh-ONE (301) menas you get ONE chance to get it right;
# three-oh-TWO (302) means you get TWO chances.
###############################################################################
# set error pages
ErrorDocument 404 {{site.baseurl}}/404.html
# turn off automatic directory indices
Options -Indexes
# turn on redirection
Options +FollowSymLinks
RewriteEngine on
# NOTE:
# Some of the below redirects are 302s, and some are 301s. 302s are used
# for redirects whose targets change sometimes. For example:
# - /docs/ -> /docs/fr/, /docs/en/, etc.
# - /docs/en/ -> /docs/en/master/, /docs/en/latest/, etc.
# - /docs/en/latest -> /docs/en/4.0.0/, /docs/en/5.0.0/, etc.
#
# 301s are for PERMANENT redirects. These are used only for mapping old
# pages to new pages.
#
# NOTE:
# (\w\w(?:-\w\w)?) - regex for languages
# (?:\d+\.(?:\d+\.\d+|x))|master|latest - regex for versions
#
# NOTE:
# Meanings of some of the flags at the ends of rules:
#
# L - terminal rule; if it applies, no more rules are checked
# R - redirect (followed by code)
# NE - no escaping special characters
# 302 (temporary):
# *.md -> *.html
RewriteRule ^(.*?)\.md$ $1.html
#RewriteRule ^.*docs/(.*?)\.md$ {{site.baseurl}}/docs/$1.html [R=302]
# 302 (temporary):
#
# docs/ -> docs/[default language]/latest/
# docs/* -> docs/*/latest/
# docs/*/ -> docs/*/latest/
# docs/*/latest -> docs/*/latest/
#
RewriteRule ^.*docs/$ {{site.baseurl}}/docs/{{site.language}}/latest/ [R=302,L]
RewriteRule ^.*docs/(\w\w(?:-\w\w)?)$ {{site.baseurl}}/docs/$1/latest/ [R=302,L]
RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/$ {{site.baseurl}}/docs/$1/latest/ [R=302,L]
RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/latest$ {{site.baseurl}}/docs/$1/latest/ [R=302,L]
# 302 (temporary):
#
# docs/*/XX/* -> docs/*/YY/*
#
{% for redirect in site.data.redirects.version-renames %}RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/{{redirect[0]}}/(.*)$ {{site.baseurl}}/docs/$1/{{redirect[1]}}/$2 [R=302,L]
{% endfor %}
# 302 (temporary):
#
# docs/XX/* -> docs/YY/*
#
{% for redirect in site.data.redirects.language-renames %}RewriteRule ^.*docs/{{redirect[0]}}/((?:\d+\.(?:\d+\.\d+|x))|master|latest)/(.*)$ {{site.baseurl}}/docs/{{redirect[1]}}/$1/$2 [R=302,L]
{% endfor %}
# 301 (PERMANENT):
#
# old docs pages -> new docs pages (global)
#
# NOTE:
# The first part of the path (i.e. the ".*") is thrown away and replaced
# by site.baseurl. It is thrown away because there is no RewriteCond to
# control whether the rewrite happens to a URI or a local file path
# (when Apache is locating the local file to serve).
{% for redirect in site.data.redirects.docs-global %}RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/((?:\d+\.(?:\d+\.\d+|x))|master|latest)/{{redirect[0]}}$ {{site.baseurl}}/docs/$1/$2/{{redirect[1]}} [NE,R=301,L]
{% endfor %}
# 301 (PERMANENT):
#
# old docs pages -> new docs pages (version-specific)
#
{% for redirect in site.data.redirects.docs %}RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/{{redirect[0]}}$ {{site.baseurl}}/docs/$1/{{redirect[1]}} [NE,R=301,L]
{% endfor %}
# 301 (PERMANENT):
#
# old pages -> new pages
#
{% for redirect in site.data.redirects.general %}RewriteRule ^.*/{{redirect[0]}}$ {{site.baseurl}}/{{redirect[1]}} [NE,R=301,L]
{% endfor %}
# rewrite only:
#
# /docs/XX/latest/* -> /docs/XX/Y.Y.Y/*
#
# NOTE:
# This does NOT return a redirect. It returns the resource *as if* the
# redirected URI was requested. That is, both URIs return the same
# resource, but the browser won't change the URI (no redirects followed).
#
# NOTE:
# This needs to be *after* the docs redirects because they might need the
# "/latest/" to be in the URI in order to activate. Placing this rule
# before them will rewrite "/latest/" to the latest version and redirects
# for "/latest/some/path.html" will never activate.
RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/latest/(.*)$ {{site.baseurl}}/docs/$1/{{site.latest_docs_version}}/$2 [L]
|