最近wordpress网站出现404错误, URL类似于:
http://www.xxxxxx.com/gallery/10-really-expensive-christmas-gifts/gallery/image/louis-vuitton-condom
http://www.xxxxxx.com/gallery/awesome-gifts-a-man-should-ask-for/gallery/image/louis-vuitton-condom
http://www.xxxxxx.com/gallery/12-must-play-christmas-songs/gallery/image/louis-vuitton-condom
......

看这地址就知道插件开启了Activate permalinks,


遂用下面地址访问
http://www.xxxxxx.com/gallery/10-really-expensive-christmas-gifts/?pid=122
发现能正常访问,初步判断应该是RewriteRules出问题了;

最后查看[NextGEN Gallery]插件源码,一步步排查,发现这个插件不支持此类型的地址
http://www.xxxxxx.com/gallery/10-really-expensive-christmas-gifts/gallery/image/louis-vuitton-condom
仅仅支持此类型的
http://www.xxxxxx.com/10-really-expensive-christmas-gifts/gallery/image/louis-vuitton-condom

打印出RewriteRules就很明白了:
代码如下
  1. [([^/]+)/gallery/page-([0-9]+)/?$] => index.php?name=$matches[1]&nggpage=$matches[2]
  2. [([^/]+)/gallery/image/([^/]+)/?$] => index.php?name=$matches[1]&pid=$matches[2]
  3. [([^/]+)/gallery/image/([^/]+)/page-([0-9]+)/?$] => index.php?name=$matches[1]&pid=$matches[2]&nggpage=$matches[3]
  4. [([^/]+)/gallery/slideshow/?$] => index.php?name=$matches[1]&show=slide
  5. [([^/]+)/gallery/images/?$] => index.php?name=$matches[1]&show=gallery
  6. [([^/]+)/gallery/tags/([^/]+)/?$] => index.php?name=$matches[1]&gallerytag=$matches[2]
  7. [([^/]+)/gallery/tags/([^/]+)/page-([0-9]+)/?$] => index.php?name=$matches[1]&gallerytag=$matches[2]&nggpage=$matches[3]
  8. [([^/]+)/gallery/([^/]+)/?$] => index.php?name=$matches[1]&album=$matches[2]
  9. [([^/]+)/gallery/([^/]+)/page-([0-9]+)/?$] => index.php?name=$matches[1]&album=$matches[2]&nggpage=$matches[3]
  10. [([^/]+)/gallery/([^/]+)/([^/]+)/?$] => index.php?name=$matches[1]&album=$matches[2]&gallery=$matches[3]
  11. [([^/]+)/gallery/([^/]+)/([^/]+)/slideshow/?$] => index.php?name=$matches[1]&album=$matches[2]&gallery=$matches[3]&show=slide
  12. [([^/]+)/gallery/([^/]+)/([^/]+)/images/?$] => index.php?name=$matches[1]&album=$matches[2]&gallery=$matches[3]&show=gallery
所以解决方法就是:
在wp-content/plugins/nextgen-gallery/lib/rewrite.php 第263行改成如下代码:
代码如下
  1. $rewrite_rules = array (
  2.   // XML request
  3.   $this->slug . '/slideshow/([0-9]+)/?$' => 'index.php?imagerotator=true&gid=$matches[1]',
  4.   // support gallery page
  5.   $this->slug . '/([^/]+)/([^/]+)/image/([^/]+)/?$' => 'index.php?gallery=$matches[1]&pid=$matches[3]',
  6. );  

然后在后台做如下操作,问题就可以解决了:
"Settings->Permalink->Save Changes"





随便说说

还可以输200