Commit c4253a5d authored by Georgios Dagkakis's avatar Georgios Dagkakis

Improve: WebSection: Fix RJS website rendering when trailing / in the URL is missing

- Make redirect to the url with slash as permanent (301)
Better for Search Engine Optimization
- Raise redirect only if request is GET
- Raise redirect only if redirect_to_added_slash property is true
- Fixup consistenct in quotes
parent 76d6ad41
......@@ -227,12 +227,19 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
self.REQUEST[self.web_section_key] = self.getPhysicalPath()
self.REQUEST.set('current_web_section', self)
actual_url = self.REQUEST.get("ACTUAL_URL", "").strip()
if actual_url and actual_url in actual_url and not actual_url.endswith("/"):
query_string = self.REQUEST.get("QUERY_STRING", "")
query_str = "?%s" % query_string if query_string else query_string
# In case we publish a Web Section and redirect_to_added_slash flag is on
# and the trailing slash is missing,
# raise a 301 redirect to the same url containing the trailing slash
actual_url = self.REQUEST.get('ACTUAL_URL', '').strip()
if getattr(self, 'getRedirectToAddedSlash', lambda: False)() and actual_url \
and self.REQUEST.get('method') == 'GET' and not actual_url.endswith('/') \
and self.REQUEST.get('PUBLISHED') == self:
query_string = self.REQUEST.get('QUERY_STRING', '')
query_str = '?%s' % query_string if query_string else query_string
return self.REQUEST.RESPONSE.redirect(
"".join([actual_url, "/", query_str]))
''.join([actual_url, '/', query_str]),
status=301
)
if not self.REQUEST.get('editable_mode') and not self.REQUEST.get('ignore_layout'):
document = None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment