常用WordPress伪静态规则(Nginx/Apache/IIS) 附固定链接设置技巧
时间:2023年12月10日
/来源:网络
/编辑:佚名
如果我们不用插件或者技术手段特殊处理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>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<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;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
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]
[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]
[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 格式。
这里有个提醒,我们在创建网站后设置固定链接,以后尽量不去修改链接,甚至以后都不要修改。必须考试就考虑好。
第一、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>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<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;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
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]
[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]
[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 格式。
这里有个提醒,我们在创建网站后设置固定链接,以后尽量不去修改链接,甚至以后都不要修改。必须考试就考虑好。
新闻资讯 更多
- 【wordpress教程】WordPress跟踪记录访客在网站的搜索词 优化网站内容和搜索体验03-31
- 【wordpress教程】Zibll子比主题的用户中心修改头像增加支持上传PNG图片文件03-31
- 【wordpress教程】wordpress报错429怎么办03-28
- 【wordpress教程】wordpress如何批量删除指定分类目录下的所有文章03-23
- 【wordpress教程】Wordpress 在文章内容的第二段后面插入广告03-03
- 【wordpress教程】WordPress纯代码禁止发表重复标题的文章03-03
- 【wordpress教程】给wordpress博客-VIEU主题评论框添加打字特效(其他主题类似)03-03
- 【wordpress教程】wordpress自动批量定时发布插件 DX-auto-publish02-08
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法