简体   繁体   中英

How to make domain redirect?

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?

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 ".

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>"; 
?>

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