From a16b24ea3bf7b75f3b8e77a094227c07314fcf37 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 8 Nov 2017 14:15:05 -0500 Subject: [PATCH] Fix deep_links macro in .htaccess Because the trailing / is optional, the deep_links macro could match multiple projects if one of their names is a prefix of the other(s) (e.g. heat and heat-translator). It also means that completely bogus paths will redirect to bogus locations - e.g. currently https://docs.openstack.org/developer/nova-foo redirects to https://docs.openstack.org/nova/latest/-foo Avoid this by adding a negative-lookahead assertion, to ensure that the path passed in by the caller of the macro is not followed by any non-/ character. Change-Id: I9dcf5dccfa36a3b1895f4422deafcdb73b150cbd --- www/.htaccess | 2 +- www/redirect-tests.txt | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/www/.htaccess b/www/.htaccess index ca588022df..66431ada9c 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -51,7 +51,7 @@ redirectmatch {{ code }} ^{{ path }}($|/.*$) {{ result }} code -- the response code (defaults to 301) #} {% macro deep_links(path, result, code=301) -%} -redirectmatch {{ code }} ^{{ path }}/?(.*)$ {{ result }} +redirectmatch {{ code }} ^{{ path }}(?![^/])/?(.*)$ {{ result }} {%- endmacro %} # Redirect old top-level HTML pages to the version under most recent diff --git a/www/redirect-tests.txt b/www/redirect-tests.txt index e27f7be9a8..c031482989 100644 --- a/www/redirect-tests.txt +++ b/www/redirect-tests.txt @@ -53,11 +53,17 @@ result_prefix -- the start of the new path (should not include /) code -- the response code (defaults to 301) #} -{% macro deep_links(path, result_prefix, code=301) -%} +{% macro deep_links(path, result_prefix, code=301, nosuffix=True) -%} {{ path }} {{ code }} {{ result_prefix }}/ {{ path }}/ {{ code }} {{ result_prefix }}/ {{ path }}/any-page {{ code }} {{ result_prefix }}/any-page {{ path }}/any-page.html {{ code }} {{ result_prefix }}/any-page.html +{%- if nosuffix %} +{{ path }}suffix 200 +{{ path }}suffix/ 200 +{{ path }}suffix/any-page 200 +{{ path }}suffix/any-page.html 200 +{% endif -%} {%- endmacro %} # Redirect old top-level HTML pages to the version under most recent @@ -102,7 +108,7 @@ # Redirect all openstack-ansible repositories appropriately {{ deep_links('/developer/ansible-hardening', '/ansible-hardening/latest') }} -{{ deep_links('/developer/openstack-ansible-foo', '/openstack-ansible-foo/latest') }} +{{ deep_links('/developer/openstack-ansible-foo', '/openstack-ansible-foo/latest', nosuffix=False) }} # Redirect some tripleo repositories appropriately {{ deep_links('/developer/tripleo-common', '/tripleo-common/latest') }}