Jump to content

Best Way To Redirect URL?


Quickquestion

Recommended Posts

I want to take this:

 

www.mysite.com/folder/someonesname

 

and forward it to this:

 

www.differentsite.com/folder/index.php?album=someonesname

 

i.e. set up an index file that will create a dynamic redirect based on the end of the URL input. What's the best way to do this? I only know a small amount of PHP.

Link to comment
https://forums.phpfreaks.com/topic/173417-best-way-to-redirect-url/
Share on other sites

EDIT:

 

Oops i completely misread the post.

best thing to do is in the folder, put in a index.html file then add a meta refresh redirect to that index.html pointing to the other url.

 

 

Probably summat like.

 

<?php
$url = $_GET['album']; 

header( 'Location: http://www.yoursite.com/'.$url.'.html' ) ;
?>

 

Or along those lines.

That isn't the best way. It also isn't search engine friendly. Do this instead:

 

<?php

$album = $_GET['album']; // Presuming that you are using a mod_rewrite command to make folder/someonesname go to xx.php?album=someonesname
header("HTTP/1.1 301 Moved Permanently"); // Send the permanently moved header for search engines and modern browsers
header("Location: http://www.differentsite.com/index.php?album=".$album); // Redirect the user

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.