如何将http://example.com重定向到http://www.example.com

时间:2011-03-10 07:32:54

标签: wordpress url-rewriting

如何使用htaccess

http://example.com重定向到http://www.example.com

2 个答案:

答案 0 :(得分:4)

使用包含以下内容的.htaccess文件:

RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

如果IIS确定,主机会侦听您要用于块的所有网址(包括www.example.com和example.com)

然后使用IIS的重写模块:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module

您可以轻松地将Apache mod_rewrite中的规则导入ISS:
http://learn.iis.net/page.aspx/470/importing-apache-modrewrite-rules

答案 1 :(得分:0)

通过正确配置DNS。 确保您有以下行:

@      IN A   your.server.ip.address

其中任何请求yourdomain.bla的人都会被发送到具有给定IP的服务器。在您的情况下,IP地址将与“www”的CNAME配置相同。

但是,如果您使用网络酒店服务,他们往往不会让客户进行默认配置。可能那时你无法进行配置。

相关问题