Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
Regex 301重定向以删除子目录和文件扩展名_Regex_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Regex 301重定向以删除子目录和文件扩展名

Regex 301重定向以删除子目录和文件扩展名,regex,apache,.htaccess,mod-rewrite,redirect,Regex,Apache,.htaccess,Mod Rewrite,Redirect,我最近迁移了一个站点,该站点的所有博客帖子都位于/blog/子目录中,因此URL的格式如下: www.example.com/blog/post name.shtml 根目录中还有如下页面: www.example.com/page name.htm 它现在迁移到WordPress,URL结构为: www.example.com/post name和www.example.com/page name。我们希望保持这种新的URL结构 我如何: 删除blog子目录 从URL中删除.html、.sht

我最近迁移了一个站点,该站点的所有博客帖子都位于
/blog/
子目录中,因此URL的格式如下:

www.example.com/blog/post name.shtml

根目录中还有如下页面:

www.example.com/page name.htm

它现在迁移到WordPress,URL结构为:

www.example.com/post name
www.example.com/page name
。我们希望保持这种新的URL结构

我如何:

  • 删除
    blog
    子目录
  • 从URL中删除.html、.shtml和.htm

  • 将此规则作为
    /.htaccess
    中的第一条规则放置:

    RewriteEngine On    
    RewriteRule ^(?:blog/)?([^.]+)\.s?html?$ /$1 [L,NC,R=301,NE]
    

    感谢您的快速回复!这会包括扩展名为.htm和.shtml的文件吗(它们在旧站点上到处都是)?旧域的根目录中的页面也如何?确定检查更新的规则。它必须是root.htaccess中的第一条规则,是的,它负责
    html
    .htm
    .shtml