100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > nginx如何将网址重定向到特定页面

nginx如何将网址重定向到特定页面

时间:2021-02-04 13:57:58

相关推荐

nginx如何将网址重定向到特定页面

我看过这个问题,该问题描述了如何在nginx中重定向网址,如下所示

# main server block for server {listen 80;server_name ;...}# redirect to server {server_name ;return 301 $scheme://$request_uri;}

我需要做的是重定向一组单独的页面,所以想知道如何做到这一点

例如\index\home\main\index.php

然后,我还有其他页面可以简单地重定向到.php扩展名

例如\about\\about.php

例如\contact到\\contact.php

做这个的最好方式是什么?

找到了答案…假设以下服务器块

server {listen 80;server_name ;...}

将适当的正则表达式位置路径添加到重定向URL ,rewritereturn将其添加到重定向URL。

\index\home\main\index.php

location ~ ^/(index|home|main) {rewrite ^/.* http://$server_name/index.php permanent;}

对于\about\\about.php

location /about {rewrite ^/.* http://$server_name/about.php permanent;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。