WordPress入门知识之伪静态规则有哪些?

廖为祥 wordpressWordPress入门知识之伪静态规则有哪些?已关闭评论443阅读模式

WordPress中如何添加伪静态规则呢?这是很多新手朋友都会面对的一个问题,那么WordPress入门知识之伪静态规则有哪些?今天小编就从 IIS/Apache/Nginx 三种环境下总结一下添加伪静态规则。

首先我们先检测一下主机是否支持伪静态,在WordPress后台> 设置 > 固定链接,设置为不是默认带?的那种结构,然后访问任何一篇文章,如果出现404错误,则就表明我们主机目前是不支持WordPress伪静态。

1.IIS伪静态规则

IIS 环境是 Windows 主机常用的服务器环境,新建一个 txt 文件,将下面的代码添加到文件中:

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

然后另存为 httpd.ini 文件,上传到WordPress站点的根目录即可。

2.Apache伪静态规则

Apache是 Linux 主机下常见的环境,现在一般的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面的代码:

<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 站点的根目录,重命名为 .htaccess 即可。

3.Nginx伪静态规则

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

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

保存,重启 Nginx 即可。

如果有宝塔面板可以直接打开网站管理添加到网站伪静态选项里,或者选择wordpress默认的伪静态

WordPress入门知识之伪静态规则有哪些?

以上就是廖为祥博客为大家分享WordPress入门知识之伪静态规则,希望能够帮助到大家。

继续阅读
廖为祥
  • 本文由 发表于 2022年12月13日 09:47:19
  • 除特别声明外,本站原创内容版权遵循 CC BY-NC-ND/2.5/CN协议规定