Nginx下Wordpress的永久链接实现(301,404等)_nginx

其实也是很简单的方法,修改nginx.conf文件,加入以下内容:

复制代码 代码如下:

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;
}
}

重启nginx就可以了。

以下是我的配置文件实例:

www# cat nginx.conf

user  www www;
worker_processes  10;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
worker_connections  1024;
}

http {
include       mime.types;
default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] $request ‘
#                  ‘”$status” $body_bytes_sent “$http_referer” ‘
#                  ‘”$http_user_agent” “$http_x_forwarded_for”‘;

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
listen       80;
server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
root   /usr/local/www/nginx;
index  index.php index.html index.htm;
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;
}

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/local/www/nginx-dist;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root           html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /usr/local/www/nginx$fastcgi_script_name;
include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

# HTTPS server
#
#server {
#    listen       443;
#    server_name  localhost;

#    ssl                  on;
#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_timeout  5m;

#    ssl_protocols  SSLv2 SSLv3 TLSv1;
#    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#    ssl_prefer_server_ciphers   on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}
}

时间: 2024-07-30 19:01:29

Nginx下Wordpress的永久链接实现(301,404等)_nginx的相关文章

Nginx下WordPress链接(url伪静态)301永久重定向实现方法_nginx

问题: 在几个blog程序中折腾的结果~ 导致url连续二次变化.这是第三次了. nginx 通过rewrite 使用 "permanent;"参数 成301永久url重定向. 以往的url结构 http://www.jb51.net/post/199/ 现在需要的url结构 http://www.jb51.net/archives/199.html 过程: 学习nginx的配置规则,学习正则表达式(我也没接触过,学呗.) nginx的中文维科:http://wiki.nginx.or

Nginx下WordPress伪静态设置教程

对于Apache和Nginx的对比网上也是一大堆了,这里就不再赘述,以后有机会详细讲解. 相信用Wordpress的博主们都会用到伪静态,伪静态的好处是对搜索引擎友好,看起来也好看. 用虚拟主机的用户大都是用Apache,Apache的伪静态Wordpress支持很好,几乎不用自己去编辑.喜爱折腾,喜爱独立博主们用VPS的还是很多的,Nginx在VPS中作为架设环境还是挺常见,但是用Nginx时Wordpress就变成瞎子一般,这里就怎样在Nginx下设置伪静态. 我们不需要了解怎样写伪静态,不

Nginx下WordPress的Rewrite

最近接触WP Super Cache,该插件要求固定链接必须是重写的,故用到Rewrite. 我的是这样配置的: /usr/local/nginx/conf/rewrite/wordpress.conf location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.ph

nginx下wordpress子目录伪静态设置步骤详解

网站访问目录为http://show.abc.com/ ,但是wordpress是装在他下面的manage目录中的,所以访问到的首页也该是http://show.abc.com/manage/ 而wordpress默认访问文章的URL是http://show.abc.com/manage/?p=12 的形式,需要做伪静态使文章访问形式为http://show.abc.com/manage/12 在nginx中配置如下: server { listen  80; server_name     s

Nginx下php文件不存在不返回404却返回No input file specified

在php解析字段加上 try_files $uri =404; 完整的php 解析字段为:  代码如下 复制代码 location ~ \.php(|/.*)$ {       try_files $uri =404;       fastcgi_pass       unix:/tmp/php-cgi.sock;       fastcgi_index      index.php;       include            fastcgi_params;       fastcgi_

解决wordpress修改固定链接页面出现404错误问题

如果你的Apache.PHP.Mysql系统架构是自己配置的,或使用的某些安装包,可能会有这个问题,具体解决办法如下: (1)Apache中的rewrite模块没有开启,在配置文件httpd.conf中去除这一行前面的#号就可以了 #LoadModule rewrite_module modules/mod_rewrite.so 变为: LoadModule rewrite_module modules/mod_rewrite.so (2)AllowOverride Not Enabled  服

LNMP下WordPress伪静态规则配置

更换了 VPS,就要开始给网站搬家,搬家出现的第一个问题就是 WordPress 的伪静态问题.新的VPS 采用了 LNMP 环境,安装的是 AMH 面板.之前使用的是LAMP环境的 Webmin,但是 Webmin 功能过于臃肿复杂,比较耗内存,而且Nginx 对比 Apache 更高效稳定.所以这次决定采用 LNMP 环境.虽说这样比较折腾,但是只有去折腾才会有意外的收获. Nignx 不支持 .htaccess 伪静态规则,需要修改 Nignx 相应的配置文件添加伪静态规则,以下记录了整个

Nginx中wordpress伪静态规则配置

因为与apache规则有一些不一样,所以我们不能直接使用apache的wordpress规则了. 费话不说多直接上代码  代码如下 复制代码 [root@localhost ~]# cat /etc/nginx/wprw.conf rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last; if (!-e $request_filename) { rewrite ^.+?(/wp-.*) $1 last; rewrite ^.+

Nginx下修改WordPress固定链接导致无法访问的问题解决_nginx

今天下午没事,像以往一样开始做seo的优化,当然牵扯到永久链接,wordpress提供多种类型的链接形式     1/%year%/%monthnum%/%day%/%postname%/     2/%year%/%monthnum%/%postname%/     3/%year%/%monthnum%/%day%/%postname%.html     4/%year%/%monthnum%/%postname%.html     5/%category%/%postname%.html