WordPress伪静态规则设置

2019-08-28 1,409 0

今天突然遇到网站只有首页能打开,内页突然都打不开的情况,网站以前使用是没有问题的,是突然出现这个情况,我后台设置-固定链接里面用的也是伪静态模式 .html 的,这个也没有动,但是内页就是404,后台才知道,原来在 .htaccess中没有wordpress的伪静态规则,我用的是虚拟主机,可能是主机服务商那边的规则变化吧,现在贴上伪静态规则设置。我是直接用第一个就可以。

伪静态:即网站本身是动态网页如.php、.asp、.aspx等格式,而这类网页还带“?”加参数来读取数据库。开启伪静态后,动态网页即被转换重写成静态网页类型页面。

WordPress和其它网站系统不一样,其它网站系统基本都带有生成静态页面功能。但Wp只能使用伪静态。

现在的主机基本都会支持伪静态功能,只需在空间后台伪静态功能,选择网站系统,空间就会支持该系统的伪静态。

如何判读空间是否支持伪静态。在网站后台:设置-固定链接,选择第一个除外,看网站其它页面是否出现404,如果是,则空间不支持伪静态。

只要空间支持伪静态重写URL Rewrite功能,根据服务器主机空间环境,只需加入下列伪静态规则即可。

1Apache伪静态规则

新建一个 txt 文件,将下面的代码添加到文件中,然后另存为.htaccess文件,上传到WordPress站点的根目录即可。

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

2Nginx规则

在Nginx中的server模块配置如下内容,打开 nginx.conf 或者某个站点的配置环境,例如 /usr/local/nginx/conf/yzipi.conf,在server{ } 大括号里面添加下面的代码。

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){

IIS伪静态规则rewrite (.*) /index.php;

}

}

3IIS伪静态规则

新建一个 txt 文件,将下面的代码添加到文件中,然后另存为 httpd.ini 文件,上传到WordPress站点的根目录即可。

[ISAPI_Rewrite]

# Defend your computer from some worm attacks

#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]

# 3600 = 1 hour

CacheClockRate 3600

RepeatLimit 32

# Protect httpd.ini and httpd.parse.errors files

# from accessing through HTTP

# Rules to ensure that normal content gets through

RewriteRule /tag/(.*) /index\.php\?tag=$1

RewriteRule /software-files/(.*) /software-files/$1 [L]

RewriteRule /images/(.*) /images/$1 [L]

RewriteRule /sitemap.xml /sitemap.xml [L]

RewriteRule /favicon.ico /favicon.ico [L]

# For file-based wordpress content (i.e. theme), admin, etc.

RewriteRule /wp-(.*) /wp-$1 [L]

# For normal wordpress content, via index.php

RewriteRule ^/$ /index.php [L]

RewriteRule /(.*) /index.php/$1 [L]

- END -

相关文章

宝塔开启系统防火墙,导致宝塔面板无法打开
谷歌广告插入附加宣传图片,可以降低每次的平均点击费用
使用Thumbnails插件处理图片缩略图及图片调用的php代码汇总
独立站和站群站点,分区别使用缓存和压缩插件
关于压缩html、css和js使网站加速的问题
linux服务器wordpress目录站群伪静态

发布评论

8 − 5 =