.htaccess 重定向匹配语法以简化这些条目
我希望在处理旧的子文件夹和人们链接到的可能的迭代时减少重定向。现在,我正在这样做:.htaccess 重定向匹配语法以简化这些条目,.htaccess,redirect,.htaccess,Redirect,我希望在处理旧的子文件夹和人们链接到的可能的迭代时减少重定向。现在,我正在这样做: RedirectMatch 301 (?i)/old-sub-folder/index.html$ https://www.website.com/new-place/ RedirectMatch 301 (?i)/old-sub-folder/$ https://www.website.com/new-place/ RedirectMatch 301 (?i)/old-sub-folder$ https://w
RedirectMatch 301 (?i)/old-sub-folder/index.html$ https://www.website.com/new-place/
RedirectMatch 301 (?i)/old-sub-folder/$ https://www.website.com/new-place/
RedirectMatch 301 (?i)/old-sub-folder$ https://www.website.com/new-place/
所以它是同一个页面,但是如果我不在这里添加每个版本,一个将转到404页面。有没有办法把它合并成一行 根据
Apache使用库提供的与Perl兼容的正则表达式
这意味着您可以使用公共前缀/old sub folder
和可选尾部(?:/|/index.html)?
构建正则表达式,例如
RedirectMatch 301 (?i)/old-sub-folder(?:/|/index.html)?$ https://www.website.com/new-place/
虽然,我不确定这是否真的是一种进步。拥有三个独立的简单正则表达式可能比一个更复杂的表达式更具可读性(和可维护性)