最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
WordPress在nginx下的URL重写规则详解
时间:2014-08-22 编辑:简简单单 来源:一聚教程网
配置代码
代码如下 | 复制代码 |
server { index index.html index.php; rewrite /wp-admin$ $scheme://$host$uri/ permanent; location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ location ~ .*\.(js|css)$ |
重启你的nginx即可
固定链接(URL重写)在nginx的规则
只是用于WordPress单站点(一般默认安装的),不是多站点哦。将以下代码插入location的root中
代码如下 | 复制代码 |
if (!-f $request_filename){ set $rule_1 1$rule_1; } if (!-d $request_filename){ set $rule_1 2$rule_1; } if ($rule_1 = "21"){ rewrite /. /index.php last; } |
我的WordPress在nginx配置情况:
代码如下 | 复制代码 |
location / { |
现在在新版本的已有不妥,会有两个规则警告提示。博友@五月里徜徉的小猫咪 说是nginx的if陷阱,分享了一个新的配置方案。方案比较全,不过如果你的conf不是那样配置的,只需要在location中插入:
try_files $uri $uri/ /index.php?$args;
发下自用的WordPress Nginx重定向规则,适合非子目录安装:
代码如下 | 复制代码 |
|
AMH自带的为:
代码如下 | 复制代码 |
location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } |
简单使用方法:AMH使用AMRewrite插件新建一条Rewrite规则,校验规则,然后编辑虚拟主机,选择新建的规则。
直接改nginx.conf了解的自然了解,不熟悉的随便就瘫了。
相关文章
- HTML简单购物数量小程序代码展示 10-31
- html canvas实现弹幕功能 10-31
- HTML中空格表示的意义 10-31
- html area标签解读 10-31
- html使用表单标签实现注册页面代码展示 10-31
- 使用HTML截图并保存为本地图片的代码展示 10-31