AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / ubuntu / Perguntas / 1229806
Accepted
Doug Smythies
Doug Smythies
Asked: 2020-04-24 06:53:30 +0800 CST2020-04-24 06:53:30 +0800 CST 2020-04-24 06:53:30 +0800 CST

Apache RedirectMatch em help.ubuntu.com não redirecionando em todos os casos

  • 772

Para 20.04, o guia do servidor Ubuntu foi movido para um novo local. Redirecionamentos foram adicionados ao arquivo .htaccess. No entanto, eles não estão funcionando para todos os URLs.

Observe que as partes relacionadas de help.ubuntu.com são publicadas a partir do branch master launchpad apenas uma vez por dia. O objetivo é acertar, como eu obviamente não fiz ontem.

Exemplo de trabalho:

https://help.ubuntu.com/20.04/serverguide/remote-administration.html.fr

vai para:

https://ubuntu.com/server/docs

Não funciona exemplo:

https://help.ubuntu.com/20.04/serverguide/remote-administration.html

retorna 404 Não encontrado.

A parte relevante do arquivo .htaccess:

# 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

Parece precisar da extensão de idioma para funcionar. Isso vai funcionar?

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

Não tenho como testar isso no meu servidor de teste, e gostaria de acertar na próxima publicação.

EDIT: Ao excluir a parte "início da linha" da expressão, acontece que posso depurar isso no meu servidor de teste, onde o local está em vários subdiretórios. Com os testes de Muru com a resposta e meus próprios testes, há é a confiança na solução.

Referências:
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
servidor web Apache - como remover extensões de linguagem

apache2
  • 1 1 respostas
  • 244 Views

1 respostas

  • Voted
  1. Best Answer
    muru
    2020-04-24T08:02:03+08:002020-04-24T08:02:03+08:00

    Em RedirectMatch(e AliasMatch), a regex é comparada com a URL. Ele não precisa corresponder ao URL inteiro, a menos que esteja ancorado para isso usando ^e $. Então, sim, sua sugestão:

    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
    

    corresponderá a ambos /20.04/serverguide/remote-administration.html.fre /20.04/serverguide/remote-administration.html. Ele também corresponderá /20.04/serverguide/remote-administration.html.frfoobar, mas, novamente, a versão original também.

    Não é tão difícil testar se você tem o Docker instalado:

    1. Obtenha a imagem do docker e a conf do Apache:

      docker run --rm httpd:2.4-alpine cat /usr/local/apache2/conf/httpd.conf > my-httpd.conf
      
    2. Edite my-httpd.confpara ter AllowOveride Allno <Directory "/usr/local/apache2/htdocs">bloco
    3. Crie seus arquivos htaccess:

      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. Crie alguns casos de teste:

      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. Execute o 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. Teste seus URLs neste servidor local do apache:

      % 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
      
    • 2

relate perguntas

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Existe um comando para listar todos os usuários? Também para adicionar, excluir, modificar usuários, no terminal?

    • 9 respostas
  • Marko Smith

    Como excluir um diretório não vazio no Terminal?

    • 4 respostas
  • Marko Smith

    Como descompactar um arquivo zip do Terminal?

    • 9 respostas
  • Marko Smith

    Como instalo um arquivo .deb por meio da linha de comando?

    • 11 respostas
  • Marko Smith

    Como instalo um arquivo .tar.gz (ou .tar.bz2)?

    • 14 respostas
  • Marko Smith

    Como listar todos os pacotes instalados

    • 24 respostas
  • Martin Hope
    Flimm Como posso usar o docker sem sudo? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    led-Zepp Como faço para salvar a saída do terminal em um arquivo? 2014-02-15 11:49:07 +0800 CST
  • Martin Hope
    ubuntu-nerd Como descompactar um arquivo zip do Terminal? 2011-12-11 20:37:54 +0800 CST
  • Martin Hope
    TheXed Como instalo um arquivo .deb por meio da linha de comando? 2011-05-07 09:40:28 +0800 CST
  • Martin Hope
    Ivan Como listar todos os pacotes instalados 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    David Barry Como determino o tamanho total de um diretório (pasta) na linha de comando? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "Os seguintes pacotes foram retidos:" Por que e como resolvo isso? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford Como os PPAs podem ser removidos? 2010-07-30 01:09:42 +0800 CST

Hot tag

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve