1

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

Doug Smythies
  • 16,146

1 Answers1

2

In RedirectMatch (and AliasMatch), 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:

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

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:

  1. Get the docker image and the Apache conf:

    docker run --rm httpd:2.4-alpine cat /usr/local/apache2/conf/httpd.conf > my-httpd.conf
    
  2. Edit my-httpd.conf to have AllowOveride All in the <Directory "/usr/local/apache2/htdocs"> block
  3. Create your htaccess files:

    mkdir foo
    cat > foo/.htaccess <<EOF
    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
    EOF
    
  4. Create some test cases:

    cat > urls <<EOF
    localhost:8080/20.04/serverguide/remote-administration.html.fr
    localhost:8080/20.04/serverguide/remote-administration.html
    localhost:8080/20.04/serverguide/serverguide.pdf
    localhost:8080/20.04/serverguide/serverguide.pdf.fr
    localhost:8080/foo/20.04/serverguide/remote-administration.htmlbar
    EOF
    
  5. Run apache:

    docker run -d --name apache -p 8080:80 -v $PWD/my-httpd.conf:/usr/local/apache2/conf/httpd.conf -v $PWD/foo:/usr/local/apache2/htdocs/ httpd:2.4-alpine
    
  6. Test your URLs against this local apache server:

    % xargs -ta urls  -n1 curl -sI
    curl -sI localhost:8080/20.04/serverguide/remote-administration.html.fr
    HTTP/1.1 301 Moved Permanently
    Date: Thu, 23 Apr 2020 15:58:34 GMT
    Server: Apache/2.4.43 (Unix)
    Location: https://ubuntu.com/server/docs
    Content-Type: text/html; charset=iso-8859-1
    
    curl -sI localhost:8080/20.04/serverguide/remote-administration.html
    HTTP/1.1 301 Moved Permanently
    Date: Thu, 23 Apr 2020 15:58:34 GMT
    Server: Apache/2.4.43 (Unix)
    Location: https://ubuntu.com/server/docs
    Content-Type: text/html; charset=iso-8859-1
    
    curl -sI localhost:8080/20.04/serverguide/serverguide.pdf
    HTTP/1.1 301 Moved Permanently
    Date: Thu, 23 Apr 2020 15:58:34 GMT
    Server: Apache/2.4.43 (Unix)
    Location: https://assets.ubuntu.com/ubuntu-server-guide
    Content-Type: text/html; charset=iso-8859-1
    
    curl -sI localhost:8080/20.04/serverguide/serverguide.pdf.fr
    HTTP/1.1 301 Moved Permanently
    Date: Thu, 23 Apr 2020 15:58:34 GMT
    Server: Apache/2.4.43 (Unix)
    Location: https://assets.ubuntu.com/ubuntu-server-guide
    Content-Type: text/html; charset=iso-8859-1
    
    curl -sI localhost:8080/foo/20.04/serverguide/remote-administration.htmlbar
    HTTP/1.1 404 Not Found
    Date: Thu, 23 Apr 2020 15:58:34 GMT
    Server: Apache/2.4.43 (Unix)
    Content-Type: text/html; charset=iso-8859-1
    
muru
  • 207,228