htaccess Redirect Problem
June 3, 2013 12:55 PM   Subscribe

Need help configuring .htaccess: parkeddomain.com redirects fine, but www.parkeddomain.com does not.

I have a parked domain name pointed to a subdirectory on my main site. Right now, the .htacces file reads:

RewriteEngine On
RewriteCond %{http_host} ^parkeddomain.com
RewriteRule ^(.*) http://maindomain.com/parkeddomain [R=301,L]

This coding was done by my hosting company. It works if you type parkeddomain.com into the browser. It does not work if you type www.parkeddomain.com.

My hosting company told me to add a rewrite condition for the www.parkeddomain.com, so the .htaccess would read:

RewriteEngine On
RewriteCond %{http_host} ^parkeddomain.com
RewriteCond %{http_host} ^www.parkeddomain.com
RewriteRule ^(.*) http://maindomain.com/parkeddomain [R=301,L]

This does not work, and their tech support is useless. I'm sure it's something simple in the code, but a Google search has not provided an answer, and this is a bit above my skill level.

Thanks in advance for your help.
posted by ljshapiro to Computers & Internet (7 answers total) 3 users marked this as a favorite
 
Try the [OR] flag after the first RewriteCond and escape the dots?
RewriteEngine On
RewriteCond %{http_host} ^parkeddomain\.com [OR]
RewriteCond %{http_host} ^www.parkeddomain\.com
RewriteRule ^(.*) http://maindomain.com/parkeddomain [R=301,L]

posted by holgate at 1:04 PM on June 3, 2013 [1 favorite]


Response by poster: Thanks, holgate. Unfortunately, it didn't work, and escaping the dots made the non-www version not work as well. If I don't escape the dots, but leave the [OR] in, the non-www version works, but the www does not.
posted by ljshapiro at 1:11 PM on June 3, 2013


Simple sanity check first: are you sure www.parkeddomain.com maps to the same IP as parkeddomain.com?
posted by zempf at 1:37 PM on June 3, 2013 [2 favorites]


Why not simply do Redirect / http://example.com/subfolder instead? If the domain is parked it hardly matters.
posted by artlung at 1:41 PM on June 3, 2013


Hm. Escape all the dots in RewriteCond (not RewriteRule) and put server variables in caps? Yeah, zempf's sanity check applies here. And check that any domain rewriting isn't being done before the request even hits the .htaccess.

Why not simply do Redirect / http://example.com/subfolder instead?

Because it would redirect traffic that's aimed at the main domain? It'd make sense if the OP had access to the VHost configuration for the parked domain, but I'm assuming this is a standard shared hosting environment where that doesn't apply.
posted by holgate at 1:45 PM on June 3, 2013


Response by poster: Just got off the phone with my hosting company, after I did another Google search which indicated that this might be a DNS problem. They added a CNAME in DNS for www.parkeddomain.com, and I'm waiting for it to propagate. As soon as I know if this solves the problem I'll close this question. Fingers crossed. Thanks!
posted by ljshapiro at 1:50 PM on June 3, 2013 [1 favorite]


Response by poster: It propagated faster than expected. This is the htaccess file that works:

RewriteEngine On
RewriteCond %{http_host} ^parkeddomain.com [OR]
RewriteCond %{http_host} ^www.parkeddomain.com
RewriteRule ^(.*) http://maindomain.com/parkeddomain [R=301,L]

Thanks, everyone
posted by ljshapiro at 1:53 PM on June 3, 2013


« Older Help me find clip-in bike shoes!   |   Design software for the homeowner? Newer »
This thread is closed to new comments.