【问题标题】:.htaccess Subdirectory Rewrite Exception.htaccess 子目录重写异常
【发布时间】:2013-08-21 10:34:18
【问题描述】:

我目前正在合并我们最近收购的网站上的帖子,该网站安装了多个 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/ 可见?

【问题讨论】:

    标签: regex wordpress .htaccess mod-rewrite url-rewriting


    【解决方案1】:

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

    【讨论】:

    • 试过这个并清除缓存来检查。它现在将转到http://domain.com/index.wml,而不是重定向到主页,但它没有显示页面(我在主安装中创建了一个显示)。有什么想法吗?
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 2019-05-28
      • 2010-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多