我设法通过 Google Domain / Google Cloud 托管了一个静态网站,但遇到了一个小问题。www.example.com 工作得很好,http://www.example.com也可以,但是当我在没有 www 的情况下做http://example.com时。它不会带我到正确的域。任何建议都会很棒。谢谢!
问问题
57 次
1 回答
0
您需要在您的域 cpanel 中设置域首选项,无论是否带有 www,如果您将其设置为http://sitename.com,它应该可以在http://sitename.com中使用,或者在您的网站 .htaccess 文件是一个示例
Example 1 - Redirect example.com to www.example.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Example 2 - Redirect www.example.com to example.com:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L]
这个 .htaccess 301 重定向的解释:
让我们看一下示例 1 - 将 example.com 重定向到 www.example.com。第一行告诉 apache 启动重写模块。下一行:
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
指定下一条规则仅在 http 主机(即查询的 url 的域)不是(- 用“!”指定)www.example.com 时触发。
于 2018-01-09T20:13:23.890 回答