AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 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

help.ubuntu.com 上的 apache RedirectMatch 在所有情况下都不会重定向

  • 772

对于 20.04,Ubuntu 服务器指南已移至新位置。重定向已添加到 .htaccess 文件中。但是,它们不适用于所有 URL。

请注意,help.ubuntu.com 的相关部分每天仅从主启动板分支发布一次。目标是做到这一点,因为我昨天显然没有做到这一点。

工作示例:

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

去:

https://ubuntu.com/server/docs

不工作的例子:

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

返回 404 未找到。

.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

它似乎需要语言扩展才能工作。这行得通吗?

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

我没有办法在我的测试服务器上对此进行测试,并希望在下一个出版物中正确使用它。

编辑:通过删除表达式的“行首”部分,事实证明我可以在我的测试服务器上调试它,该位置是几个子目录。通过 Muru 的答案测试和我自己的测试,有是对解决方案的信心。

参考资料:
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 服务器 - 如何去除语言扩展

apache2
  • 1 1 个回答
  • 244 Views

1 个回答

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

    在RedirectMatch(and AliasMatch) 中,正则表达式与 URL 匹配。它不必匹配整个 URL,除非使用^and锚定这样做$。所以,是的,你的建议:

    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
    

    将匹配/20.04/serverguide/remote-administration.html.fr和/20.04/serverguide/remote-administration.html。它也将匹配/20.04/serverguide/remote-administration.html.frfoobar,但随后,原始版本也匹配。

    如果你安装了 Docker,测试起来并不难:

    1. 获取 docker 镜像和 Apache conf:

      docker run --rm httpd:2.4-alpine cat /usr/local/apache2/conf/httpd.conf > my-httpd.conf
      
    2. 编辑my-httpd.conf到块AllowOveride All中<Directory "/usr/local/apache2/htdocs">
    3. 创建您的 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. 创建一些测试用例:

      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. 运行阿帕奇:

      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. 针对此本地 apache 服务器测试您的 URL:

      % 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

相关问题

  • 如何使用 fastcgi 和简单的测试脚本设置 apache?

  • 新贵监督的 Apache 初始化脚本?

  • http://localhost/ 不工作

  • 访问启用的虚拟主机时出现 403 禁止错误

  • 如何设置一台机器来将我的网站托管到世界各地 - 使用我自己的网址?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

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

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve