2016-11-18 32 views
2

Url https://example.com/profile/chico 必须被nginx理解为: https://example.com/profile/?username=chico(当前工作的url)。翻译的url路径查询nginx的参数

https://example.com/profile/当前工作为好,因为它解决了目前到index.php,没有用户名PARAM。

我现在有

location /profile/ { 
    index /profile/index.php; 
} 

有在网络上关于这个很多不同的东西,我没有具体是什么,我需要找到。

也试过

location /profile/ { 
    rewrite ^/profile/(.*)$ /profile/?username=$1; 
} 

回答

2

尝试:

location /profile/ { 
    try_files $uri @rewrite; 
} 
location @rewrite { 
    rewrite ^/profile/(.+)$ /profile/index.php?username=$1 last; 
    rewrite^/profile/index.php last; 
} 

如果第一rewrite比赛,第二rewrite被忽略。在使用.php扩展名重写URI后,处理将移至不同的location块。

查看this document了解更多。

编辑:添加try_files块来处理静态内容。

+0

谢谢你,走近了404(例如/profile/assets/js/main.js工作,页面使用用户名VAR实际负载,但在资产上的页面结果不能被发现,同样的图像和css文件) –

+0

好的,没有意识到你在那个位置有静态内容。答案已更新。 –

+0

太棒了。谢谢。 –