apache设置Permalinks以后,除了首页,所有的页面都变成了404错误。

多方查找原因,发现是.htaccess文件未生效。在apache配置文件中设置WordPress目录权限为AllowOverride All:

 <Directory /www/veryi.com/w>
   AllowOverride All
   Order allow,deny
   Allow from all
 </Directory>
访问正常。

附固定链接设置方法:

linux服务器,登陆WordPress,单击“设置”。然后单击“设置”的下级分类‘固定链接’在常规设置中选择“自定义”,然后在“自定义结构”中填入你想设置的永久链接结构。我用的是:

/%post_id%.html

Windows服务器下设置WordPress固定链接伪静态,只要主机支持自定义404页面,无需安装插件,就能让Win主机像Linux 那样,方便使用WordPress的固定链接为静态化地址格式。

<?php
header(”HTTP/1.1 200 OK”);
$ori_qs = $_SERVER['QUERY_STRING'];
$pattern = ‘/[^;]+;[^:]+:\/\/[^\/]+(\/[^\?]*)(?:\?(.*))?/i’;

preg_match($pattern, $ori_qs, $matches);
$_SERVER['PATH_INFO'] = $matches[1] . ‘?’ . $matches[2];
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
$query_args = explode(’&’, $matches[2]);
unset($_GET);
foreach ($query_args as $arg)
{
$the_arg = explode(’=', $arg);
$_GET[$the_arg[0]] = $the_arg[1];
}
include(’index.php’);
?>

设置固定链接(Permalink)伪静态步骤:
1. 将以上代码保存为 404.php,并上传至主机根目录。
2. 设置 404 自定义错误页为 404.php。
3. 进入 WordPress 控制面板,设置(Options)- 固定链接(Permalinks),选择固定链接格式。

nginx静态链接还需要设置重写规则:               
        location /w/ {
            # enable search for precompressed files ending in .gz
            # nginx needs to be complied using –-with-http_gzip_static_module
            # for this to work, comment out if using nginx from aptitude
            gzip_static on;
           
            # if the requested file exists, return it immediately
            if (-f $request_filename) {
            break;
            }
           
            set $supercache_file '';
            set $supercache_uri $request_uri;
           
            if ($request_method = POST) {
            set $supercache_uri '';
            }
           
            # Using pretty permalinks, so bypass the cache for any query string
            if ($query_string) {
            set $supercache_uri '';
            }
           
            if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
            set $supercache_uri '';
            }
           
            # if we haven't bypassed the cache, specify our supercache file
            if ($supercache_uri ~ ^(.+)$) {
            set $supercache_file /w/wp-content/cache/supercache/$http_host/$1index.html;
            }
           
            # only rewrite to the supercache file if it actually exists
            if (-f $document_root$supercache_file) {
            rewrite ^(.*)$ $supercache_file break;
            }
           
            # all other requests go to WordPress
            if (!-e $request_filename) {
            rewrite . /w/index.php last;
            }

原创文章,转载请注明: 转载自素食勤俭敬老孝慈

本文链接地址: 设置WordPress固定链接不生效的可能原因

文章的脚注信息由WordPress的wp-posturl插件自动生成

Tags: , ,

2,168 views

One Comment to “设置WordPress固定链接不生效的可能原因”

  1. 请教 说道:

    通过404跳转,会不会影响搜索引擎收录,不会被认为作弊吧

    [回复]

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">