通过配置文件,设置IIS,Nigix和Apach下WordPress站点的伪静态规则

首先,检测主机是否支持伪静态的方法

WordPress后台 > 设置 > 固定链接,设置为自定义。自定义后面的空里面填写%post_id%.htm。然后访问任何一篇文章,如果出现 404 错误,说明你的主机当前不支持 WordPress 伪静态。文章源自原紫番博客-https://www.yuanzifan.com/53877.html

设置伪静态方法:文章源自原紫番博客-https://www.yuanzifan.com/53877.html

1.IIS伪静态规则文章源自原紫番博客-https://www.yuanzifan.com/53877.html

IIS方法一:IIS 环境是 Windows 主机常用的服务器环境,新建一个 txt 文件,将下面的代码添加到文件中:文章源自原紫番博客-https://www.yuanzifan.com/53877.html

然后另存为 httpd.ini 文件,上传到WordPress站点的根目录即可。文章源自原紫番博客-https://www.yuanzifan.com/53877.html

[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方法二:文章源自原紫番博客-https://www.yuanzifan.com/53877.html

创建web.config文件,写入如下内容,并将文件放置到网站根目录下:文章源自原紫番博客-https://www.yuanzifan.com/53877.html

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

  <system.webServer>

    <rewrite>

      <rules>

                <rule name="category">

                    <match url="category/?(.*)" />

                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />

                    <action type="Rewrite" url="/index.php?category_name={R:1}" appendQueryString="false" logRewrittenUrl="false" />

                </rule>

                <rule name="tags">

                    <match url="tag/?(.*)" />

                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />

                    <action type="Rewrite" url="index.php?tag={R:1}" />

                </rule>

                <rule name="Main Rule" stopProcessing="true">

                    <match url=".*" />

                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">

                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

                    </conditions>

                    <action type="Rewrite" url="index.php/{R:0}" />

                </rule>

                <rule name="wordpress" patternSyntax="Wildcard">

                    <match url="*" />

                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">

                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

                    </conditions>

                    <action type="Rewrite" url="index.php" />

                </rule></rules>

    </rewrite>

  </system.webServer>

</configuration>

2.Apache伪静态规则
Apache是 Linux 主机下常见的环境,现在一般的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面的代码:文章源自原紫番博客-https://www.yuanzifan.com/53877.html

然后上传到 WordPress 站点的根目录,重命名为 .htaccess 即可文章源自原紫番博客-https://www.yuanzifan.com/53877.html

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

IIS方法二:文章源自原紫番博客-https://www.yuanzifan.com/53877.html

3.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;

4.宝塔面板一键配置:

后台网站-设置-伪静态,选择Wordpress

站长微信
扫码添加(注明来意)
weinxin
Yuanzifan99
原梓番博客公众号
博客内容精选
weinxin
原梓番博客
 最后更新:2019-9-30

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证