【问题标题】:Exclude a directory recursively from 301 redirect using .htaccess使用 .htaccess 从 301 重定向中递归排除目录
【发布时间】:2016-05-12 06:27:09
【问题描述】:

我刚刚在地址 http://lifeworks.life 上推出了一个新网站(基于 Wix)。我已经在http://lifeworkslearningcetner.com/archive 存档了旧网站(WordPress),将除一个.htaccess 文件之外的所有文件从http://lifeworkslearningcenter.com 的根文件夹中移出,以保持重定向和SEO 源源不断。

我有特定的重定向工作,以及根级重定向。但是现在,http://lifeworkslearningcenter.com/archive 的 URL 重定向到了 https://www.lifeworks.life/archive,它不存在并以 404 结尾。

这是我正在使用的 .htaccess 代码。我想要的是能够正常访问/archive文件夹中的WordPress站点,前端和后端都可以。

RewriteEngine on

RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^about-lifeworks$ "https\:\/\/www\.lifeworks\.life\/team\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^services$ "https\:\/\/www\.lifeworks\.life\/services\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^methodology$ "https\:\/\/www\.lifeworks\.life\/approach\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^sign-up$ "https\:\/\/www\.lifeworks\.life\/enroll\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^rates-and-policies$ "https\:\/\/www\.lifeworks\.life\/policies\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^contact-us$ "https\:\/\/www\.lifeworks\.life\/contact\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^blog$ "https\:\/\/www\.lifeworks\.life\/blog\.html" [R=301,L]

Redirect 301 / http://lifeworks.life/

【问题讨论】:

    标签: wordpress apache .htaccess redirect


    【解决方案1】:

    您的最后一条语句 (Redirect ...) 没有条件,因此始终会将您重定向到 lifeworks.life。 为了从重定向中排除 /archive 请求,您可以使用类似以下的内容来代替您的 Redirect 语句:

    RewriteCond %{HTTP_HOST} !^lifeworks\.life$
    RewriteCond %{REQUEST_URI} !^/archive
    RewriteRule ^(.*)$ http://lifeworks.life/$1 [R=301,L]
    

    【讨论】:

    • 我试过这个,它似乎没有做任何事情。我清除了缓存,并将其移至 .htaccess 文件的底部,但无济于事。
    • 我忘了添加 -- 我尝试用 lifeworkslearningcenter.com 替换 lifeworks.life,因为这是我需要排除文件夹的站点。
    • !^lifeworks\.life$ 用于防止重定向循环,意思是“如果它不是 lifeworks.life”。你必须保持这种状态。
    • 明白了。好的,我尝试在文件底部添加您的确切代码,并清除了我的缓存,但它不起作用。
    • 为了确定,您删除了文件底部的Redirect 声明?
    猜你喜欢
    • 2018-04-26
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 2014-03-22
    • 2012-12-18
    • 2022-11-27
    • 2012-09-23
    相关资源
    最近更新 更多