.htaccess mod_rewrite 301重定向嵌套异常?

时间:2012-03-25 03:09:01

标签: apache .htaccess mod-rewrite redirect

在部署之前,我需要对我的.htaccess提供一些帮助!

我想301将几乎的所有内容从elementalthreads.com重定向到ethreads.com,不包括blog / wp-content / uploads和/ pommo。

我这样做了吗?:

RewriteEngine on
#exclude old uploads folder and /pommo
RewriteCond %{REQUEST_URI} !^/(blog/wp-content/uploads|pommo) [NC]
RewriteRule (.*) http://ethreads.com/$1 [R=301,L]

这会转移规范的网页页面吗?

这是我知道我需要帮助的地方:

  1. 旧网站有一个wordpress博客,我已经克隆到新域名。我希望保留永久链接,这些几乎 1:1,例如: http://www.elementalthreads.com/blog/ethreads-now-on-amazon-com/重定向到
    http://ethreads.com/ethreads-now-on-amazon-com/(注意/博客/此处缺失)

  2. 博客索引http://www.elementalthreads.com/blog/应该重定向到http://ethreads.com/blog/,这似乎是上述规则的一个例外,因为“/ blog /”应该只保留在这里?

  3. 我对如何regEx或以其他方式定义最后两个条件/规则感到困惑。任何帮助都将非常感激!

1 个答案:

答案 0 :(得分:1)

这对我来说是正确的。但是,你不应该在没有检查的情况下放这个,没有什么能阻止你测试它。要记住的一件事是浏览器可以缓存301响应代码,因此在测试时应使用[R,L]作为标记。一旦您满意,请在部署之前重新添加[R=301,L]

确定点(1)& (2)

# only redirect the blog direcotry
RewriteRule ^blog/?$            http://ethreads.com/blog/ [NC,R=301,L]

# redirect all sub folders of blog to the new domain
RewriteRule ^blog/([\w-])/?$    http://ethreads.com/$1/ [NC,R=301,L]