Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 重定向匹配语法以简化这些条目_.htaccess_Redirect - Fatal编程技术网

.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/
虽然,我不确定这是否真的是一种进步。拥有三个独立的简单正则表达式可能比一个更复杂的表达式更具可读性(和可维护性)