【问题标题】:htaccess: non-www to www but only when no subdomain is sethtaccess:非 www 到 www 但仅在未设置子域时
【发布时间】:2014-10-26 02:09:11
【问题描述】:

我想要这个:

domain.tld 到 www.domain.tld

和其他子域:sub.domain.tld 没有重定向到 www.sub.domain.tld

【问题讨论】:

    标签: .htaccess redirect web apache2


    【解决方案1】:

    您可以将此代码放在您的 htaccess 中(在根文件夹中)

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

    【讨论】:

    • 然后他将 sub.domain.tld 重定向到 www.domain.tld
    • 没有。这只会在 domain.tldwww.domain.tld 时重定向。否则它不会重定向任何东西
    • 你的意思是我的主机在开玩笑?!
    • 哦,对不起,他妈的缓存。我一直在尝试相同的子域。另一个子域工作。谢谢!
    • 如果可能,我会在 5 分钟内接受您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 2012-10-17
    • 2014-12-22
    • 1970-01-01
    相关资源
    最近更新 更多