@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/
的内容)都会重定向到根文件夹。
我们尝试了从htaccess到http://winginx.com/en/htaccess提供的Nginx的翻译,
location ~ ^/category/((?!index|images|menu)[^/]+)/?$ {
rewrite ^(.*)$ /$1 redirect;
}
但这没有用。
答案 0 :(得分:1)
出于某种原因,当我们最终放弃寻找解决方案并最终寻求帮助时,我们很快就会找到一个。这是 - 它完美地运作:
rewrite ^/category/((?!index|images|menu)[^/]+)/(.*)$ /$1 permanent;