6

我已经在 webfaction 上共享托管,我想让 www.mydomain.com 转发到 mydomain.com,就像 www.stackoverflow.com 重定向到 stackoverflow.com 一样。在 webfaction 控制面板中,我设置了一条将 www.mydomain.com 子域链接到 mydomain.com 的 CNAME 记录,但这似乎不起作用。也许是什么搞砸了 mydomain.com 是一个虚拟主机并且没有 IP 地址的 A 记录?

无论如何,有人能帮我找出正确的方法吗,无论是在 webfaction 控制面板中还是直接在 httpd.conf 文件中?提前致谢。

4

1 回答 1

9

The solution I use is to create a Static/CGI/PHP application (which I call redirect), and place an .htaccess file at its root. I point all the domains and subdomains that need redirecting to this application, and I then populate the .htaccess file with all the necessary redirection directives for my server, like so:

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

It works well, and because it is instantaneous, it's easy to debug.

于 2011-04-13T02:22:50.057 回答