常用WordPress伪静态规则(Nginx/Apache/IIS) 附固定链接设置技巧

如果我们不用插件或者技术手段特殊处理WordPress程序的话,我们常规都会用到WordPress伪静态功能。比如我们看到的WordPress建站笔记内容的.html地址实际上并不是静态文件而是伪静态文件,这个是当下比较流行的文件格式。由于系统的问题,我们有些环境下需要我们手工设置WordPress伪静态规则,在这里麦子准备整理当前Nginx、Apache、IIS 三个引擎下的伪静态设置。

第一、WordPress伪静态设置规则

如果有服务器环境和WEB环境自带的,那我们直接用系统自带规则,如系统没有自带,则需要什么手工部署。

1、Apache

一般我们虚拟主机会用到Linux Apache环境,这个伪静态文件在我们网站根目录 .htaccess 文件中,我们需要添加。

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

将代码丢进这个文件中,然后我们就可以设置WordPress固定链接,实现伪静态。

2、Nginx

Nginx 是我们比较常用的WEB引擎。如果系统没有自带配置,我们需要自己配置。

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

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

这个具体需要根据我们的环境,设置到对应站点的 .conf 文件中。

3、IIS

IIS 是我们常用的Windows系统引擎,一般我们很少用WIN用来搭建WP程序,因为WP兼容比较好的是LiNUX系统。

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

这需要配置到IIS系统站点的httpd.ini文件中生效。

第二、WordPress固定链接设置

我们很多朋友都知道如何设置固定链接,当前如果用动态链接不利于搜索引擎和用户体验,现在大家都用伪静态或者静态链接。

WordPress固定链接设置

我们可以看到上图,在【设置】-【固定链接】然后我们可以选择固定给的日期和名称类型、月份和名称类型、数据型、文章名型的链接样式。或者我们可以根据实际需要设置,我们可以自定义结构。比如麦子用的是 ID.html 格式。

这里有个提醒,我们在创建网站后设置固定链接,以后尽量不去修改链接,甚至以后都不要修改。必须考试就考虑好。

投票 post
© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享