Generate URL Alias?? in PHP

2019-02-26 01:54发布

问题:

I just saw this somewhere, and I'm interested on it, and can't seemed to find it anywhere or I just used the wrong words to search for.

Well I saw this link,

http://splur.gy/r/QqVYf/r/2tgNklHgmVK

and when I clicked it, I got redirected to other page which called

https://www.facebook.com/xxx.xxx?sk=app_xxxx

Anyone knows how this thing was made? or just a little hint to start off?

A help would be nice. :)

回答1:

These are done with RewriteRule, a simple Google search willgive you mroe details.

In short, the URL will be broken down sorta like this: (Line 1, URL part, Line 2, PHP relative.

http://splur.gy
http://splur.gy/index.php

r
$_GET['var_1']

QqVYf
$_GET['var_2']

r
$_GET['var_3']

2tgNklHgmVK
$_GET['var_4']

The RewriteMod will take the URL as setup in the above format, and pass the varialbes to a script. It is another way of posting variables in the URL.

As you see above: stackoverflow.com/posts/15182831, does not actually have a file named posts/15182831, it is simple used as a variable, passed to a script which queries that database, and spits out results based on what the script says.



回答2:

You will need to have a server that will allow you to rewrite requests so you can redirect all requests to a single script. If you are running Apache, you would create an .htaccess file with something like this in it:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^r$ /redirect.php [L,QSA]
RewriteRule ^r/(.*) /redirect.php?__q=/$1 [L,QSA]
</IfModule>

Then if you go to http://yourdomain.com/r/234243/adsfsd, the request will be sent to the script /redirect.php and '234243/adsfsd' will be passed as the GET paramiter 'q'.

Then you would create a file called redirect.php that would process the request and then redirect the user. It might look somthing like this:

<?php

$redirection = process_to_determine_location_from_query( $_GET['q'] ); 

header( 'Location: {$redirection}' );

?>


回答3:

It's called a redirect. You can do it in PHP with this code:

<?php
header('http://example.com');

Another thing that might have happened is that the link you saw was not the actual link you follow when you click. It's as simple as doing this:

<a href="http://aha-gotcha.com">example.com</a>



回答4:

Anyone could do that.

http://www.google.com/

It has nothing to do with PHP.



标签: php url