【问题标题】:.htaccess causing endless loops, unable to rewrite .net to .com with a blog.htaccess 导致无限循环,无法使用博客将 .net 重写为 .com
【发布时间】:2010-12-17 15:27:09
【问题描述】:

我有一个带有 .com 和 .net 的域,它们都指向同一个位置。我需要将主站点和博客都映射到一个 url,因为谷歌正在抨击我重复的内容。这是一个 PHP 网站和一个 Wordpress 博客。

最终目标是将这两个集合中的每一个重写为两个不同的 URL。这可能吗?如果不可能,有人可以推荐我最接近的选择吗?或者也许我应该删除.net。

.com 是主站点,.net 停放在同一个物理位置。

otown411.com
www.otown411.com
otown411.net
www.otown411.net
--------------------
otown411.com   <--- **goal rewrite of any 4 above**


blog.otown411.com
blog.otown411.net
www.otown411.com/blog
www.otown411.net/blog
otown411.com/blog
otown411.net/blog
---------------------
blog.otown411.com  <--- goal rewrite from any six above

这是我能得到的最接近的,它可以很好地处理顶部,任何使博客部分工作的尝试都会导致无限循环:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{http_host} !^otown411\.com$ [NC]
RewriteRule ^(.*)$ http://otown411.com/$1 [R=301,NC,QSA,L]

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    这应该可以解决问题:

    Options +FollowSymLinks
    RewriteEngine on
    # Handle Blog first
    
    RewriteCond %{HTTP_HOST} !^blog\.otown411\.com [NC] # check we're not where we want to be
    RewriteCond %{HTTP_HOST} ^blog\. [NC,OR] # only if subdomo is blog OR...
    RewriteCond %{REQUEST_URI} .*blog/.* [NC] # blog/ is in the URL
    RewriteRule ^(blog/)?(.*?)$ http://blog.otown411.com/$2 [R=301,QSA,L]
    
    # Now handle the rest
    
    RewriteCond %{HTTP_HOST} !^blog\.otown411\.com [NC] # don't process for blog nor
    RewriteCond %{HTTP_HOST} !^otown411\.com$ [NC] # if we're already on otown411.com
    RewriteRule ^(.*)$ http://otown411.com/$1 [R=301,NC,QSA,L] 
    

    【讨论】:

    • 我今天一定花了两个小时搞砸了这个问题,而你得到的结果已经非常完美了,可以投票了。唯一不同的是:www.otown411.com/blog 变成了 otown411.com/blog,但我很高兴,谷歌现在应该是。 TYVM
    猜你喜欢
    • 2013-12-12
    • 2013-06-25
    • 1970-01-01
    • 2015-10-25
    • 2019-04-01
    • 1970-01-01
    • 2015-02-21
    • 2013-12-20
    • 1970-01-01
    相关资源
    最近更新 更多