Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/64453-htaccess-re-direct-from-domain-alias/
Share on other sites

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 :)

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.