Dragen Posted August 12, 2007 Share Posted August 12, 2007 Hi. I'm wanting to get a domain alias for one of my sub-domains, but my host says that I can only get a domain alias on my full domain name and not a sub-domain... Not sure if this is just my host, but hey. What I wondering is, can I get htacces to determine the incoming url and re-direct depending on what it is? for example.. I have a domain name: www.mydomain.com A subdomain: www.sub.mydomain.com and an alias: www.anotherdomain.com (which link to www.mydomain.com) Then if someone goes to www.mydomain.com, it lets the user access mydomain.com, but if the user goes to www.anotherdomain.com, then have it re-direct to www.sub.domain.com. I'm not sure if I can do this as I'm not brilliant at htaccess re-directs, so if anyone can help it'd be great! thanks Quote Link to comment https://forums.phpfreaks.com/topic/64453-htaccess-re-direct-from-domain-alias/ Share on other sites More sharing options...
Dragen Posted August 12, 2007 Author Share Posted August 12, 2007 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/64453-htaccess-re-direct-from-domain-alias/#findComment-321692 Share on other sites More sharing options...
Wuhtzu Posted August 12, 2007 Share Posted August 12, 2007 You can do this: .htaccess: This will redirect all traffic to http://www.sub.domain.com Redirect 301 / http://www.sub.domain.com/ index.php: This will redirect all trafic to http://www.sub.domain.com <?php header("Location: http://www.sub.domain.com"); exit; ?> I don't know if the .htaccess method redirects if the user requests a page that does not exist like www.anotherdomain.com/page/that/does/not/exist.html. Chances are it will just throw a 404 Quote Link to comment https://forums.phpfreaks.com/topic/64453-htaccess-re-direct-from-domain-alias/#findComment-321696 Share on other sites More sharing options...
Dragen Posted August 12, 2007 Author Share Posted August 12, 2007 thanks wuhtzu. I'm not wanting to re-direct everyone though. Because mydomain.com and anotherdomain.com will be pointing to the same place (mydomain.com) I want to re-direct just people who type in anotherdomain.com into the url. could I perhaps do something like: Redirect 301 http://anotherdomain.com http://www.example.com/newpage.html or maybe: RewriteCond %{HTTP_REFERER} !^http://(www\.)?anotherdomain.com/.*$ [NC] RewriteRule ^.* htpp://www.sub.domain.com/ [L] As already noted I'm not too brilliant with htacces, but hopefully what I've suggested is somewhat okay? Quote Link to comment https://forums.phpfreaks.com/topic/64453-htaccess-re-direct-from-domain-alias/#findComment-321717 Share on other sites More sharing options...
Wuhtzu Posted August 12, 2007 Share Posted August 12, 2007 If you have these three domains all on the same server (at the same host using apache virtual hosts) and they each point at a folder with their name: www.domain.com /domain.com/ www.sub.domain.com /sub.domain.com/ www.anotherdomain.com /anotherdomain.com/ Then by placing a .htaccess-file in /anotherdomain.com/.htaccess with "Redirect 301 / http://www.sub.domain.com" will redirect users typing www.anotherdomain.com in the browser to www.sub.domain.com. But if both www.domain.com and www.anotherdomain.com points at the same document root e.g. /domain.com/ you might get lucky with "Redirect 301 http://anotherdomain.com http://www.sub.domain.com" but I'm not sure, because some redirection might already be in use by your host. Quote Link to comment https://forums.phpfreaks.com/topic/64453-htaccess-re-direct-from-domain-alias/#findComment-321763 Share on other sites More sharing options...
Dragen Posted August 12, 2007 Author Share Posted August 12, 2007 hmm.. yeah. the problem is they're both pointing to the same root and the sub-domain is on a different server.. I'll have to give it a try and let you know what happens! Quote Link to comment https://forums.phpfreaks.com/topic/64453-htaccess-re-direct-from-domain-alias/#findComment-321769 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.