温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何在WordPress中设置一个伪静态规则

发布时间:2020-12-11 14:36:28 来源:亿速云 阅读:251 作者:Leah 栏目:开发技术

如何在WordPress中设置一个伪静态规则?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

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

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

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

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

如何在WordPress中设置一个伪静态规则

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

Apache伪静态规则

新建一个 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>

Nginx规则

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

}

}

IIS伪静态规则

新建一个 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]

关于如何在WordPress中设置一个伪静态规则问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI