Generate URL Alias?? in PHP

后端 未结 4 611
刺人心
刺人心 2021-01-22 04:55

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,



        
相关标签:
4条回答
  • 2021-01-22 05:36

    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.

    0 讨论(0)
  • 2021-01-22 05:39

    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}' );
    
    ?>
    
    0 讨论(0)
  • 2021-01-22 05:43

    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>

    0 讨论(0)
  • 2021-01-22 05:46

    Anyone could do that.

    http://www.google.com/

    It has nothing to do with PHP.

    0 讨论(0)
提交回复
热议问题