【问题标题】:Non-www to www and redirect to specific TLD非 www 到 www 并重定向到特定 TLD
【发布时间】:2018-07-02 04:17:15
【问题描述】:

我有以下将非 www 或 www example.co.uk 重定向到 www.example.com

RewriteCond %{HTTP_HOST} ^(www\.)?exaxmple\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.exaxmple.com/$1 [R=301,L]

但它不会将 http://example.com 重定向到 www.example.com

是否有一个简洁的规则来匹配所有条件?

【问题讨论】:

    标签: apache .htaccess url-rewriting


    【解决方案1】:

    您可以使用这些规则:

    #redirect example.com to www.example.com
    RewriteCond %{HTTP_HOST} ^example.com$
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]
    #redirect example.co.uk to example.com
    RewriteCond %{HTTP_HOST} ^(www\.)?exaxmple\.co\.uk$ [NC]
    RewriteRule ^(.*)$ http://www.exaxmple.com/$1 [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-12
      • 2012-06-03
      • 2018-06-06
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多