【问题标题】:RewriteRule - section and subsectionRewriteRule - 部分和小节
【发布时间】:2022-01-13 00:09:16
【问题描述】:

我需要将所有小节重定向到新的 URL 作为 .htaccess 中的重写规则。

示例:

  • example.com/section => example.com/new_section

  • example.com/section/subsection1 => example.com/new_section

  • example.com/section/subsection1/subsubsection => example.com/new_section

等(每个部分都有很多小节和规则从所有部分/小节有数百条规则)

我已经重写了:

RewriteRule ^section[/]?$ /new_section [R=301,L]

此重定向仅将 URL www.example.com/section 重定向到 www.example.com/new_section,但不重定向 www.example.com/section/subsection1 等。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:
    RewriteRule ^section[/]?$ /new_section [R=301,L]
    

    正则表达式^section[/]?$ 仅匹配sectionsection/。您还需要匹配section/<anything>。例如:

    RewriteRule ^section($|/) /new_section [R=301,L]
    

    注意:首先使用 302(临时)重定向进行测试,以避免潜在的缓存问题。

    所有部分/子部分的规则有数百条规则

    不确定您的意思是什么,但规则的顺序可能很重要。一般来说,更具体的规则需要先行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 2018-10-04
      • 2023-01-03
      相关资源
      最近更新 更多