Always add trailing slashes in the urls of Web Sections and Web Sites
(First some background, that also gives rationale.)
In ERP5 when we have erp5/web_site_module/web_site_xxx/web_section_xxx
and erp5/web_site_module/web_site_xxx/web_section_xxx/
they both return response code 200, and the user is typically directed to the same section. This causes duplicate content, that is bad for search engine optimisation.
For this reason, I started to check on what can be done and I asked @romain, who told me that also he for RenderJS to work, it is needed that trailing slash is always there. @gabriel worked on this some time ago, but without finalising. Explanation why RenderJS needs this in the message of 76b9d574
So I started from Gabriel's work and did required extensions.
(end of background)
This merge request introduces:
- In Web Section, if the URL does not have a trailing slash, we raise a redirect (302) to the url with the slash added.
- In Web Section we override
absolute_url
andabsolute_url_path
to return the url with the trailing slash. This is done to reduce redirects. This affects also Web Site behaviour (since it inherits from Web Section) - In Web Site, we make sure that when that language support does not create wrong urls now
- There are some PythonScripts, like Base_doLanguage that had to be updated, since they use absolute_url of Web Section
- There is the issue of having actions defined like
${object_url}/xxx
, this now would return a double slash for Web Section. Generally, I think we should consider if such string definitions are the optimal, but the last commit 15b56f47 opts to provide compatibility with such definitions.
One big issue with this change, is that absolute_url now is different between Web Section/Site and other types. This is not optimal, but it would be dangerous to raise redirect all the time making sites slower.
Tests pass here (not the same revision you'll see, but because I just rebased and tests have not run yet), but it was run on the head of this.
Note I squashed @gabriel 's commits, his initial ones are here. I did not make any squash that includes both gabriel's and my commits together, in order to keep the author, even though the change in Web Section could semantically be one commit.
Since this affects a lot ERP5 Web and subsequently all projects that have web mode, I need to cc @nexedi Please provide comments and ideas