【问题标题】:301 redirect non-www and www to new domain but exclude homepage/root301 将非 www 和 www 重定向到新域但排除主页/根
【发布时间】:2014-08-28 10:28:05
【问题描述】:

olddomain.com 有一些指向它的有毒链接。 我想将 www 和非 www 页面重定向到 newdomain.com。 非www重定向不起作用.. root 不应重定向到 newdomain.com

RewriteEngine On
RewriteBase /

# www homepage redirect
RedirectPermanent olddomain.com http://www.olddomain.com

RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ [NC]
#if not root
RewriteCond %{REQUEST_URI} !^/?$ [NC]
#redirect
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite redirect


    【解决方案1】:

    这条规则就足够了:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
    RewriteRule ^((?!css-images/).+)$ http://www.newdomain.com/$1 [R=301,L,NE,NC]
    

    通过使用.+,它将不会重定向主页。

    【讨论】:

    • 这很好用!我刚刚发现我需要一个不应重定向到 www.newdomain.com 的“css-images/”文件夹。有没有办法让这个例外?
    猜你喜欢
    • 2011-04-01
    • 1970-01-01
    • 2018-05-01
    • 1970-01-01
    • 2013-06-26
    • 1970-01-01
    • 2014-04-09
    • 2017-05-03
    • 1970-01-01
    相关资源
    最近更新 更多