WordPress在nginx下的URL重写规则详解
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-17 15:56:00 浏览: 评论:0
下文中整理了在nginx中配置wordpress博客的URL重写规则了,包括了整站配置与固定链接配置了,下面我们就一起来看看吧.
配置代码,代码如下:
- server {
- listen 80;
- server_name www.phpfensi.com phpfensi.com;
- access_log /data/logs/nginx/www.phpfensi.com.access.log main;
- index index.html index.php;
- root /data/site/www.phpfensi.com;
- location / {
- try_files $uri $uri/ /index.php?$args;
- add_header Pragma "public";
- expires 12h;
- }
- 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)$ {
- access_log off;
- log_not_found off;
- expires max;
- }
- location ~ \.php$ {
- try_files $uri =404;
- fastcgi_split_path_info ^(.+\.php)(/.+)$;
- #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
- include fastcgi_params;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- # fastcgi_intercept_errors on;
- fastcgi_pass 127.0.0.1:9000;
- }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
- {
- expires 24h;
- access_log off;
- }
- location ~ .*\.(js|css)$
- {
- expires 24h;
- access_log off;
- }
重启你的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;
- } //phpfensi.com
- if ($rule_1 = "21"){
- rewrite /. /index.php last;
- }
我的WordPress在nginx配置情况,代码如下:
- location / {
- root html/xiedexu.cn;
- index index.php index.html index.htm;
- 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;
- }
- add_header Cache-Control private;
- }
现在在新版本的已有不妥,会有两个规则警告提示,博友@五月里徜徉的小猫咪 说是nginx的if陷阱,分享了一个新的配置方案,方案比较全,不过如果你的conf不是那样配置的,只需要在location中插入:
try_files $uri $uri/ /index.php?$args;
发下自用的WordPress Nginx重定向规则,适合非子目录安装,代码如下:
- location / {
- try_files $uri $uri/ /index.php?$args;
- }
- rewrite /wp-admin$ $scheme://$host$uri/ permanent;
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了解的自然了解,不熟悉的随便就瘫了.
Tags: WordPress重写规则 URL重写规则
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)