Subdomain Redirect


#1

Hey guys,

Forgive me if this sounds too easy. I’ve been trying to create subdomains, and been having difficulty. I tried following the wiki directions, but it doesn’t really spell out making the subdomain. What I want to do is make www.mysite.com/amazon, and have that link redirect to my affiliate amazon site, so it’s not shown that it’s an affiliate link on the site.

I clicked “Add Domain/Subdomain” and whenever I try to put in mysite.com/amazon it says error. How do I make a new subdomain this way? Thank you


#2

I am not exactly sure what you are trying to achieve, but mysite.com/amazon is not a sub-domain, it is merely a directory under your existing domain, which is why the panel is throwing the error. Something like amazon.mysite.com would be a valid sub-domain.

Perhaps I have misunderstood what you are trying to achieve. If so, provide some more details and I’ll do my best to help.

Mark


Save [color=#CC0000]$50[/color] on DreamHost hosting using promo code [color=#CC0000]SAVEMONEY[/color] ( Click for promo code details )


#3

The most simple way to do that is creating the folder named amazon, then creating a file named index.php in it, with the following code in it: (simply open the file in notepad and paste the code into it)

<?php header("Location: [b]url[/b]"); ?> Replace url with the URL (address) of the site you want to redirect to, for example http://www.amazon.com.

Note that there [color=#CC0000]cannot[/color] be anything above the <?php tag or PHP will exit with an error.


#4

What Raz said is correct if you want a subdomain and what coma said will work if you meant a directory.

Another option would be to create a redirect script if you’re going to be doing this a lot. Something that will do what coma said, but for multiple sites. You could have a PHP script called something like go.php. Then link it something like http://www.domain.com/go.php?amazon and the script will 301 to where you want it.

Here’s a basic example of what you could do (I tested it to make sure it worked). Put this in go.php (or any other name):

[code]<?php
$links = array(
‘amazon’ => ‘http://www.amazon.com’,
‘dreamhost’ => ‘http://www.dreamhost.com
);

if (array_key_exists($_SERVER[‘QUERY_STRING’], $links)) {
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: {$links[$_SERVER[‘QUERY_STRING’]]}”);
} else {
die(‘Invalid URL’);
}
?>[/code]You would get to Amazon by linking to http://www.yourdomain.com/go.php?amazon

Switch amazon to dreamhost and you’d end up at DH.

Enter something invalid and the script will die. That, and keeping an array of allowed links, will keep people from trying to use it to hide spam links. A bad idea/example would be having a redirect script that takes any full URL as the variable and will redirect to it.

Just keep adding as many links as you want in the links array, using that format, and you won’t have to create a directory for every link that does basically the same thing.

You could also setup the “else” to redirect somewhere, rather than die, like your homepage or something.

And of course, that’s a very basic example. If you had a ton of links, you could tie it in with a database. You could strtolower() everything to make it case-insensitive, etc.


:stuck_out_tongue: Save up to $96 at Dreamhost with ALMOST97 promo code (I get $1).
Or save $97 with THEFULL97.


#5

Or, perhaps simpler, you can create a .htaccess file redirecting whatever URL pathnames within the domain you want to whatever sites you want.

– Dan