Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP redirect to another website

I have a directory named "goto" and a file inside called index.php. Currently the following is inside the index.php file:

<?php
$url = $_GET['url'];
header("Location: $url");
?>

At the moment to redirect to another URL I have to type this into the address bar:

http://mysite.com/goto/?url=http://google.com

I would appreciate it if you could tell me how I could change that URL so that I could redirect the user to a website by typing this into the address bar:

http://mysite.com/goto/http://google.com
like image 617
max_ Avatar asked Jul 10 '26 22:07

max_


2 Answers

Use mod_rewrite and .htaccess to rewrite http://mysite.com/goto/http://google.com as http://mysite.com/goto/?url=http://google.com

RewriteEngine On
RewriteRule ^goto/(.+)$ /goto/?url=$1 [L]

Depending on your server configuration you may need to include a / in your rewrite path (i.e., ^/goto/(.+)$).

like image 134
ide Avatar answered Jul 13 '26 13:07

ide


Unless you want to become a malware hub, I would wholeheartedly recommend you not doing this.

If you wish to allow redirect in such a manner, using http://mysite.com/goto/google and then work out the domain from a whitelist of available, allowed, destinations.

like image 42
corrodedmonkee Avatar answered Jul 13 '26 14:07

corrodedmonkee



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!