VPS侦探论坛

 找回密码
 注册
查看: 4948|回复: 6

Nginx伪静态规则疑惑

[复制链接]
发表于 2013-9-16 13:25:51 | 显示全部楼层 |阅读模式

  1. if ($request_uri ~ "/+[^\.]+$"){
  2. rewrite ^/(.+[^/])$ $request_uri/ permanent;}
复制代码

上面这段代码加到nginx中是为了解决伪静态访问 http://域名/abc 后自动补上一个/
但是在根目录下有一个真实的文件夹 archiver
访问 http://域名/archiver 时就成下面这样,后面出现了好多个/
http://域名/archiver/////////////////////
请大家指点迷津!
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2013-9-16 14:52:10 | 显示全部楼层


默认的伪静态可能有些问题的
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2013-9-16 15:36:33 | 显示全部楼层

  1. rewrite ^([^.\?]*[^/])$ $1/ permanent;
复制代码

这样试试
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2013-9-16 18:49:42 | 显示全部楼层

回复 3# 的帖子




军哥,改为:rewrite ^([^.\?]*[^/])$ $1/ permanent;  这样也不行。
访问 http://域名/archiver 或 http://域名/archiver/ 会自动跳转到首页
http://域名/forum.php

[ 本帖最后由 !@#123 于 2013-9-16 18:51 编辑 ]
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2013-9-16 20:33:08 | 显示全部楼层

只是在目录后加/ 是没问题的,可能你的伪静态有干扰。

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2013-9-16 21:07:31 | 显示全部楼层

伪静态规则是这样的,请军哥指点迷津。
  1. rewrite ^([^\.]*)/(\w+)-type-([0-9]+)-([0-9]+)/$ $1/forum.php?mod=forumdisplay&fid=$2&typeid=$3&typeid=$3&filter=typeid&page=$4 last;
  2. rewrite ^([^\.]*)/(\w+)-sort-([0-9]+)-([0-9]+)/$ $1/forum.php?mod=forumdisplay&fid=$2&sortid=$3&sortid=$3&filter=sortid&page=$4 last;
  3. rewrite ^([^\.]*)/gid-([0-9]+)/$ $1/forum.php?gid=$2 last;
  4. rewrite ^([^\.]*)/tag/$ $1/misc.php?mod=tag last;
  5. rewrite ^([^\.]*)/tag-(thread|blog)-([0-9]+)-([0-9]+)/$ $1/misc.php?mod=tag&id=$3&type=$2&page=$4 last;
  6. rewrite ^([^\.]*)/tag-([0-9]+)/$ $1/misc.php?mod=tag&id=$2 last;
  7. rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
  8. rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
  9. rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
  10. rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
  11. rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
  12. rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
  13. rewrite ^([^\.]*)/tid-([0-9]+)-([0-9]+)/$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D1&page=$3 last;
  14. rewrite ^([^\.]*)/tid-([0-9]+)/$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D1&page=1 last;
  15. rewrite ^([^\.]*)/(\w+)-fid-([0-9]+)/$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
  16. if (!-e $request_filename) {
  17. rewrite ^([^\.]*)/(\w+)/$ $1/forum.php?mod=forumdisplay&fid=$2&page=1 last;
  18. }
  19. rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
  20. if (!-e $request_filename) {
  21. return 404;
  22. }
复制代码
 楼主| 发表于 2013-9-17 00:03:14 | 显示全部楼层

感谢军哥,已解决!
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-25 01:23 , Processed in 0.027955 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表