For 20.04 the Ubuntu serverguide has moved to a new location. Redirects have been added to the .htaccess file. However, they are not working for all URLs.
Note that the related parts of help.ubuntu.com are published from the master launchpad branch only once per day. The objective is to get this right, as I obviously didn't yesterday.
Working example:
https://help.ubuntu.com/20.04/serverguide/remote-administration.html.fr
goes to:
https://ubuntu.com/server/docs
Not working example:
https://help.ubuntu.com/20.04/serverguide/remote-administration.html
returns 404 Not Found.
The relevant portion of the .htaccess file:
# For 20.04, and likely onwards, the serveguide has moved.
# Don't try to be too clever, just force the base page and drop the rest.
#
RedirectMatch permanent ^/(stable|lts|20\.04)/(serverguide/.+\.html)\..* https://ubuntu.com/server/docs
RedirectMatch permanent ^/(stable|lts|20\.04)/(serverguide/.+\.pdf)\..* https://assets.ubuntu.com/ubuntu-server-guide
It seems to need the language extension to work. Will this work?
RedirectMatch permanent ^/(stable|lts|20\.04)/(serverguide/.+\.html) https://ubuntu.com/server/docs
RedirectMatch permanent ^/(stable|lts|20\.04)/(serverguide/.+\.pdf) https://assets.ubuntu.com/ubuntu-server-guide
I do not have a way to test this on my test server, and would like to get it right in the next publication.
EDIT: By deleting the "start of line" part of the expression, it turns out that I can debug this on my test server, where the location is several sub-directories in. With Muru's testing with the answer and my own testing, there is confidence in the solution.
References:
https://help.ubuntu.com/
https://code.launchpad.net/~ubuntu-core-doc/help.ubuntu.com/help.ubuntu.com
https://bazaar.launchpad.net/~ubuntu-core-doc/help.ubuntu.com/help.ubuntu.com/view/head:/.htaccess
Apache web server - how to strip language extentions
In
RedirectMatch
(andAliasMatch
), the regex is matched against the URL. It doesn't have to match the whole of the URL, unless anchored to do so using^
and$
. So, yes, your suggestion:will match both
/20.04/serverguide/remote-administration.html.fr
and/20.04/serverguide/remote-administration.html
. It will also match/20.04/serverguide/remote-administration.html.frfoobar
, but then agin, the original version did as well.It's not that difficult to test if you have Docker installed:
Get the docker image and the Apache conf:
my-httpd.conf
to haveAllowOveride All
in the<Directory "/usr/local/apache2/htdocs">
blockCreate your htaccess files:
Create some test cases:
Run apache:
Test your URLs against this local apache server: