Reputation: 43
So to make it simple:
Let say my domain is greenexample.com
. Now using my domain, I want to make the link:
GreenExample.com/amazon321
Redirect to:
Amazon.com
Without using meta refresh.
I want to make multiple link re-directs like this.
So how do I do it in index.php, or do I need to create a new php file in my file directory for each link?
If so, what would the php code be to do so?
Upvotes: 2
Views: 165
Reputation: 22947
To do it with a PHP file, create an index.php
file in the amazon321
directory with the following:
<?php
header("Location: http://www.amazon.com");
exit;
?>
An alternative, and probably a better way, would be to use Redirect
directives in your .htaccess
file instead. (Assuming you're on a linux based server.)
Redirect /amazon321 http://www.amazon.com
Redirect /amazon123 http://www.amazon.com
You can even get fancier than this by using mod_rewrite
directives. For example, you could capture certain criteria in the URL and pass it on.
RewriteEngine On
RewriteRule ^amazon/(.*)$ http://www.amazon.com/$1 [R]
In the example, anything after amazon/
is found and replaced where the $1
is. So "http://www.greenexample.com/amazon/12345" would redirect to "http://www.amazon.com/12345".
Upvotes: 3
Reputation: 3414
Use header location
Code :
<?php
header("location:http://www.Amazon.com");
exit;
?>
You can show the javascript redirect
<?php
echo "<script>location.href='http://www.Amazon.com'</script>";
?>
Upvotes: 0