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
This commit is contained in:
parent
d515a8953b
commit
a16b24ea3b
@ -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
|
||||
|
@ -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') }}
|
||||
|
Loading…
Reference in New Issue
Block a user