Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Page Redirect Using URL

I want my index.php to redirect to my welcome/index.html. I know there are so many ways to do it but I want to shorten it just like Facebook does. I want a url based redirection. I want to redirect index.php to welcome/index.html by using url.

For example:

example.com to example.com/?url=welcome
//this 'url=welcome' is the index.html of my welcome folder.
like image 330
J II Jr. Avatar asked Nov 29 '25 16:11

J II Jr.


1 Answers

Here's the code, according to what I've understood. Place it on the very top of index.php. I'm assuming you're using the domain example.com

<?php 

$destination = $_GET["url"];

switch($destination) {
    case "welcome": // add your destinations here, one per single "case"
    case "about":
    case "anotherpage":
        header("Location: /" . $destination . "/index.html");
    break;   
    default:
        echo "Error";
    break;
}

?>

Doing this way you can manage which redirects will work and what not, avoinding "evil" usages of your redirect system.

Something malicious like example.com?url=http://evilsite.com will not redirect them to evilsite.com

This is probably not the best solution, but it's a good starting point to avoid not wanted redirections.

like image 190
napolux Avatar answered Dec 02 '25 06:12

napolux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!