繁体   English   中英

.htaccess子目录重写异常

[英].htaccess Subdirectory Rewrite Exception

我目前正在整合我们最近收购的一个站点上的帖子,该站点上有多个WordPress安装用于管理内容,一个安装在public_html文件夹中,另一个安装在子目录中,如下所示:

1. http://domain.com/
2. http://domain.com/another-install/

我们将所有内容从/another-install/移至主设置,并使用301重定向从所有旧链接中删除/another-install/ ,如下所示:

RedirectMatch 301 ^/another-install/(.*) http://domain.com/$1

结果所有文章都这样重定向:

http://domain.com/another-install/article-name/
TO
http://domain.com/article-name/

问题是,我们要保持/another-install/作为页面可见。 使用当前重定向, http://domain.com/another-install/转到http://domain.com/ 有什么方法可以添加例外或重写当前规则,以使其保持/another-install/可见?

将您的正则表达式从(.*) (与任何字符的0或多个匹配)更改为(.+) (与任何字符的1或多个匹配)。 这意味着在/another-install/之后必须要有一些东西才能进行重定向。

您需要一个RewriteRule来指定排除项。 将此添加到您的.htaccess文件

RewriteCond %{REQUEST_URI} !^/old-install/(index\.wml)?$ [NC]
RewriteRule ^old-install/(.+)$ http://domain.com/$1 [R=301,NC,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM