NginxApacheIIS系统环境下WordPress伪静态规则设置

NginxApacheIIS系统环境下WordPress伪静态规则设置,第1张

Nginx/Apache/IIS系统环境下WordPress伪静态规则设置 文章目录

  • 三、IIS环境下添加WordPress伪静态规则

WordPress是目前使用最为广泛的博客程序,简单直观的 *** 作,强大的第三方插件,可以让任何零基础的朋友搭建自己的个人站点。


使用WordPress建站的朋友,应该都比较习惯设置固定链接来实现伪静态地址访问,这样使整个站点的URL地址更为简单美观。


但是经常会在设置固定链接后,访问会出现直接404错误找不到页面提示,那就是你的主机不支持WordPress伪静态规则。



WordPress遇到设置固定链接自定义结构时出现404错误,解决办法很简单,只需在主机添加WordPress伪静态规则即可。


当然不同的环境下,添加的方法是不一样的。


我们常用的环境一般是Nginx/Apache/IIS三种,下面就详细介绍Nginx/Apache/IIS环境下如何配置WordPress伪静态规则。



一、Nginx环境下添加WordPress伪静态规则:

Nginx环境下添加WordPress伪静态规则只需在站点“www.xxx.com.conf”文件中的server   { } 中添加下面代码即可。


location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) /index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) /index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

二、Apache环境下添加WordPress伪静态规则:

Apache环境下方法比较简单,一般虚拟主机使用的就是此环境。


我们只需在网站根目录下的.htaccess文件中添加下面代码即可。


如果站点根目录没有此文件,那么就自己新建一个记事本,把下面内容复制到记事本,然后另存为.htaccess文件再上传到站点根目录即可。


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

三、IIS环境下添加WordPress伪静态规则

也有些朋友在Windows系统中搭建WordPress站点,但一般比较少,如果习惯使用Windows系统的朋友遇到确实伪静态规则的情况,可以使用下的规则脚本。


自己新建一个记事本,把下面内容复制到记事本,保存为web.config,然后丢到网站根目录下,且需要检查服务器是否安装IIS URL Rewrite模块,如果没有则还需要去安装。


<?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>

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/578518.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)

保存