关于wordpress如何设置伪静态IIS/Apache/Nginx

我们打开网站的时候后缀都是html结尾,看上去很美观,我们只需要设置伪静态即可,在wordpress中设置非常的简单,首先我们确定你的主机是支持伪静态的,如果你是用的宝塔面板,那么我们无需设置规则,只需要在伪静态栏目选择wordpress即可设置。

在设置伪静态的时候首先需要打开后台,选择设置,固定链接,自定义结构后缀加入/%post_id%/.html 如下图:

如果你是宝塔面板,我们只加入规则只需要打开伪静态,然后选择wordpress就会自动加入规则后保存即可。

 

如果不是宝塔面板,自行加入代码,那么如下图示:

IIS伪静态规则
IIS 环境一般是 Windows 主机常用的服务器环境,建立一个 txt 文件,将下方的代码添加到文件中即可,注意另存为 httpd.ini 文件,在传到根目录即可。

[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]

Apache伪静态规则
Apache是 Linux 主机下常见的环境,现在一般的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面的代码:(记得命名为 .htaccess 在传至根目录即可)

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Nginx伪静态规则
Nginx环境一般是Linux 主机 VPS或服务器用户用的比较多,这些用户一般都会自己配置Nginx,或者有专门的人帮你配置,打开 nginx.conf 或者某个站点的配置环境,比如 wpdaxue.com.conf(不同人配置的不一样),在 server { } 大括号里面添加下面的代码:

location / {
	try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

站长温馨提示:如果你是个人站点,数据或内容等配置并不高,那么使用Linux 主机并配置Nginx这是最佳选择,因为Nginx更加轻巧,然而Apache更加稳定,各有所优。然后也有很多人安装Windows 系统,但是同样的配置安装Linux 要比Windows打开网页快上许多,不占内存。

未经老牛允许不得转载哦

文章标题:老牛小站 » 关于wordpress如何设置伪静态IIS/Apache/Nginx

原文链接:https://www.jzb85.com/241/.html

发布信息:文章由【老牛小站】于<2021-10-22>发布于【web前端】分类下

相关标签:

关联推荐

评论 抢沙发