简体   繁体   中英

Using .htaccess to control a 'parked' domain

My question is to ask if the level of domain name control I'd like with .htaccess is even possible, and how it might be achieved.

Here's the current situation. At the moment I have a main domain (call it primary.com) that has several language variants, under a file structure like

/lang/chinese
/lang/russian

etcetera. I decided to create a sub-domain for just one of them, so now I have china.primary.com. Of course I created a .htaccess file to make all variants of primary.com and www.primary.com point to the same place (www.primary.com), and now also china.primary.com points to www.primary.com/lang/chinese. Everything works well.

Next I added a second domain (secondary.com) as a 'parked' domain on the site. A little fight with .htaccess and now I have all requests for any version of secondary.com being rewritten as a call to www.primary.com. All good. Then comes the final finesse that is the nub of my question.

While I have anything.secondary.com point to www.primary.com at the moment, is it possible to add in an exception for the possible case where a user tries to access china.secondary.com? In that event I'd like it rewritten to china.primary.com and pointed at www.primary.com/lang/china. Note I have not created a sub-domain china.secondary.com as my understanding is that it shouldn't be necessary. I think this either can or can't be done through .htaccess alone. Please excuse my iinexperience: what I have works but has been copy & pasted together as a result of finding various examples online. Here is what I have that works well right now - except the final line I added that because I hoped it would solve this, but it doesn't work. Do I actually have to create a sub domain china.secondary.com for this to work? If so my goal is dead in the water since I cannot create a subdomain on a parked domain, I believe.

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^primary.com [NC]
RewriteRule ^(.*)$ http://www.primary.com$1 [L,R=301]
RedirectMatch 301 ^/lang/chinese/(.*)$ http://china.primary.com/$1


RewriteCond %{http_host} ^secondary\.com [nc]
RewriteRule ^(.*)$ http://www.primary.com/$1 [R=permanent,nc,L]
RedirectMatch 301 ^/lang/chinese/(.*)$ http://china.primary.com/$1

Steered in the right direction by Anubhava I researched this question even more. It seems a basic assumption of mine was incorrect. It looks like you do need to create a subdomain in order to steer people away from it with .htaccess. Seems deeply counter-intuitive to me, but there it is.

Of course I cannot create a sub-domain on a domain that is merely parked with a hosting company, so attempting to support users who mistype a specific subdomain.parkeddomain.com (where they meant to type subdomain.maindomain.com) is in fact, not possible. Very surprising to me indeed, but I learnt something of value. Thank you all those that looked in on this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM