【问题标题】:Redirect .com to .org in .htaccess将 .com 重定向到 .htaccess 中的 .org
【发布时间】:2019-09-05 07:11:22
【问题描述】:

我有 domain.com 和 domain.org 作为指向同一个虚拟主机的别名。如何使用 .htaccess 将所有 domain.com 请求重定向到 domain.org?

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    您可以使用mod_rewrite 来执行此操作。

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^example\.org$
    RewriteRule ^ http://example.org%{REQUEST_URI} [L,R=301]
    

    此规则会将未发送至 example.org 的每个请求重定向到相同的请求。

    【讨论】:

    • 如果服务器是具有其他主机的虚拟服务器怎么办。仅将 widget.com 重定向到 widget.org 的 mod_rewrite 规则可能是什么样的?会是 RewriteCond %{HTTP_HOST} ^widget\.com$ 谢谢
    • 试试这个:RewriteCond %{HTTP_HOST} \.(example\.com|example\.org)$|^example\.com$
    • 奇怪的问题:您个人要求我们使用此代码 sn-p 的归属吗?或者我可以绕过它吗?我什至不知道如何根据 CC 3.0 正确地给出归属
    • @D.Tate 来自页面页脚:“用户贡献在cc by-sa 3.0attribution required 下获得许可”
    • @D.Tate 至少包含此答案的 URL。
    【解决方案2】:

    domain.com的所有www/非www重定向到domain.org

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.org/$1 [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-03
      • 2016-11-17
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多