Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
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.
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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.

about 4 years ago · Santiago Trujillo Report

0

Not really sure if this would help, but you're welcome to try

<?php 
  if (isset($_GET["url"])) {
    $url = $_GET['url'];
    header('Location:'.$url);
  }
 ?>

I haven't tried this, but this is what I thought after seeing your post

about 4 years ago · Santiago Trujillo Report

0

somewhere i read using header for redirection is little bit dangerous as header can b changed easily by hacker and hacker can send victim to another location easily. so i use javascript location.href function for redirection.

<?php
echo "<script>window.location ='http://example.com/welcome/index.html</script>";
?>

if you want to send user to dynamic url from example.com you can set a get variable like.

source address: http//example.com?url=http://example.com/welcome.html destination address: http://example.com/welcome.html

<?php
if(isset($_GET['url']))
echo "<script>window.location ='$_GET[url]'</script>";
else
echo "<script>window.location='http://somewhereelse.com'";
?>

now u can dynamically set url variable in your source address and redirect user wherever you want to

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!