【问题标题】:Redirecting the content of a directory, except for the directory itself and some of its subdirectories and files on Nginx重定向目录的内容,除了目录本身及其在 Nginx 上的一些子目录和文件
【发布时间】:2016-03-18 02:38:01
【问题描述】:

@Starkeen 在Redirecting the content of a directory, but not the directory itself as well as some of its subdirectories and files 为 Apache 配置解决了这个问题,但我们很快就会迁移到 Nginx。

他非常优雅的 Apache 解决方案:

RedirectMatch ^/category/((?!index|images|menu)[^/]+)/?$ /$1

这里,/category/ 目录中的所有内容——除了/category/index.php/category/images/ 的内容和/category/menu/ 的内容——都被重定向到根文件夹。

我们尝试了在http://winginx.com/en/htaccess 提供的从 htaccess 到 Nginx 的翻译,

location ~ ^/category/((?!index|images|menu)[^/]+)/?$ {
rewrite ^(.*)$ /$1 redirect;
}

但这没有用。

【问题讨论】:

    标签: .htaccess redirect nginx


    【解决方案1】:

    由于某种原因,当我们最终放弃寻找解决方案并最终寻求帮助时,我们通常很快就会找到解决方案。在这里——它完美地工作:

    rewrite ^/category/((?!index|images|menu)[^/]+)/(.*)$ /$1 permanent;
    

    【讨论】:

      猜你喜欢
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2013-10-30
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多