Generate URL Alias?? in PHP

后端 未结 4 737
刺人心
刺人心 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: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:

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

    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:

    
    

提交回复
热议问题