.htaccess 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ---
  2. ---
  3. ###############################################################################
  4. # WARNING
  5. ###############################################################################
  6. # Only modify this file if you know what you're doing. This file has
  7. # the potential to make pages become PERMANENTLY UNREACHABLE. If in
  8. # doubt, refer to these links:
  9. #
  10. # RewriteRule - http://httpd.apache.org/docs/current/mod/mod_rewrite.html
  11. # RewriteRule flags - http://httpd.apache.org/docs/current/rewrite/flags.html
  12. # .htaccess tester - http://htaccess.madewithlove.be/
  13. #
  14. # And remember: three-oh-ONE (301) menas you get ONE chance to get it right;
  15. # three-oh-TWO (302) means you get TWO chances.
  16. ###############################################################################
  17. # set error pages
  18. ErrorDocument 404 {{site.baseurl}}/404.html
  19. # turn off automatic directory indices
  20. Options -Indexes
  21. # turn on redirection
  22. Options +FollowSymLinks
  23. RewriteEngine on
  24. # NOTE:
  25. # Some of the below redirects are 302s, and some are 301s. 302s are used
  26. # for redirects whose targets change sometimes. For example:
  27. # - /docs/ -> /docs/fr/, /docs/en/, etc.
  28. # - /docs/en/ -> /docs/en/dev/, /docs/en/latest/, etc.
  29. # - /docs/en/latest -> /docs/en/4.0.0/, /docs/en/5.0.0/, etc.
  30. #
  31. # 301s are for PERMANENT redirects. These are used only for mapping old
  32. # pages to new pages.
  33. #
  34. # NOTE:
  35. # (\w\w(?:-\w\w)?) - regex for languages
  36. # (?:\d+\.(?:\d+\.\d+|x))|dev|latest - regex for versions
  37. #
  38. # NOTE:
  39. # Meanings of some of the flags at the ends of rules:
  40. #
  41. # L - terminal rule; if it applies, no more rules are checked
  42. # R - redirect (followed by code)
  43. # NE - no escaping special characters
  44. # 302 (temporary):
  45. #
  46. # docs/ -> docs/[default language]/latest/
  47. # docs/* -> docs/*/latest/
  48. # docs/*/ -> docs/*/latest/
  49. # docs/*/latest -> docs/*/latest/
  50. #
  51. RewriteRule ^.*docs/$ {{site.baseurl}}/docs/{{site.language}}/latest/ [R=302,L]
  52. RewriteRule ^.*docs/(\w\w(?:-\w\w)?)$ {{site.baseurl}}/docs/$1/latest/ [R=302,L]
  53. RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/$ {{site.baseurl}}/docs/$1/latest/ [R=302,L]
  54. RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/latest$ {{site.baseurl}}/docs/$1/latest/ [R=302,L]
  55. # 302 (temporary):
  56. #
  57. # docs/*/XX/* -> docs/*/YY/*
  58. #
  59. {% 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]
  60. {% endfor %}
  61. # 302 (temporary):
  62. #
  63. # docs/XX/* -> docs/YY/*
  64. #
  65. {% for redirect in site.data.redirects.language-renames %}RewriteRule ^.*docs/{{redirect[0]}}/((?:\d+\.(?:\d+\.\d+|x))|dev|latest)/(.*)$ {{site.baseurl}}/docs/{{redirect[1]}}/$1/$2 [R=302,L]
  66. {% endfor %}
  67. # 301 (PERMANENT):
  68. #
  69. # old docs pages -> new docs pages (global)
  70. #
  71. # NOTE:
  72. # The first part of the path (i.e. the ".*") is thrown away and replaced
  73. # by site.baseurl. It is thrown away because there is no RewriteCond to
  74. # control whether the rewrite happens to a URI or a local file path
  75. # (when Apache is locating the local file to serve).
  76. {% for redirect in site.data.redirects.docs-global %}RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/((?:\d+\.(?:\d+\.\d+|x))|dev|latest)/{{redirect[0]}}$ {{site.baseurl}}/docs/$1/$2/{{redirect[1]}} [NE,R=301,L]
  77. {% endfor %}
  78. # 301 (PERMANENT):
  79. #
  80. # old docs pages -> new docs pages (version-specific)
  81. #
  82. {% 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]
  83. {% endfor %}
  84. # 301 (PERMANENT):
  85. #
  86. # old pages -> new pages
  87. #
  88. {% for redirect in site.data.redirects.general %}RewriteRule ^.*/{{redirect[0]}}$ {{site.baseurl}}/{{redirect[1]}} [NE,R=301,L]
  89. {% endfor %}
  90. # rewrite only:
  91. #
  92. # /docs/XX/latest/* -> /docs/XX/Y.Y.Y/*
  93. #
  94. # NOTE:
  95. # This does NOT return a redirect. It returns the resource *as if* the
  96. # redirected URI was requested. That is, both URIs return the same
  97. # resource, but the browser won't change the URI (no redirects followed).
  98. #
  99. # NOTE:
  100. # This needs to be *after* the docs redirects because they might need the
  101. # "/latest/" to be in the URI in order to activate. Placing this rule
  102. # before them will rewrite "/latest/" to the latest version and redirects
  103. # for "/latest/some/path.html" will never activate.
  104. RewriteRule ^.*docs/(\w\w(?:-\w\w)?)/latest/(.*)$ {{site.baseurl}}/docs/$1/{{site.latest_docs_version}}/$2 [L]
  105. # Redirect http to https
  106. # From Cordova PMC Member raphinesse
  107. # https://s.apache.org/An8s
  108. # If we receive a forwarded http request from a proxy...
  109. RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
  110. # ...or just a plain old http request directly from the client
  111. RewriteCond %{HTTP:X-Forwarded-Proto} =""
  112. RewriteCond %{HTTPS} !=on
  113. # Redirect to https version
  114. RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]