Php 如何在nginx中缩短url

Php 如何在nginx中缩短url,php,nginx,Php,Nginx,我试图重写动态网址短网址没有运气 url是http://exmple.com?user=username 我试过了 rewrite ^/(.*)$ /index.php?user=$1; 我想简而言之: http://exmple.com/site/user name 所以有两个问题: 如果我将url缩短为http://exmple.com/username 如何使用其他url查询,如http://exmple.com?search=something 我该怎么做??) 我到处都在寻找答案,

我试图重写动态网址短网址没有运气 url是
http://exmple.com?user=username

我试过了

rewrite ^/(.*)$ /index.php?user=$1;
我想简而言之:

http://exmple.com/site/user name
所以有两个问题:

  • 如果我将url缩短为
    http://exmple.com/username
    如何使用其他url查询,如
    http://exmple.com?search=something

  • 我该怎么做??)


  • 我到处都在寻找答案,但没有找到任何比这更感谢您的帮助的地方

    如果我假设当有
    /site
    时,后面总是用户名,那么就这样做

    RewriteRule ^/(\/index\.php\?user=)([A-Za-z0-9_-]+)/$ /site/$1
    
    location ^~ /site/(.*) {
      try_files /index.php?user=$1&$query_string =404
    }
    

    未知指令重写规则这是
    apache
    格式,请注意问题被标记为
    nginx
    @user3040832,什么意思,“无”?请说得更具体些。
    location ^~ /site/(.*) {
      try_files /index.php?user=$1&$query_string =404
    }