Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webfaction subdomain forwarding

I have shared hosting on webfaction and I want to have www.mydomain.com forward to mydomain.com, in the same way that www.stackoverflow.com redirects to stackoverflow.com. In the webfaction control panel I set up a CNAME record linking the www.mydomain.com subdomain to mydomain.com, but this doesn't seem to be working. Maybe what's messing it up is that mydomain.com is a virtual host and doesn't have an A record to an IP address?

Anyway, can someone help me figure out the right way to do this, either in the webfaction control panel or directly in the httpd.conf file? Thanks in advance.

like image 441
danny Avatar asked Feb 21 '11 04:02

danny


1 Answers

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.

like image 104
tttallis Avatar answered Oct 17 '22 15:10

tttallis