常用WordPress伪静态规则 - Apache/Nginx/IIS系统环境
根据惯例,老蒋在给公司项目部署WordPress程序的时候习惯性的会去简单设置固定链接,然后实现伪静态URL地址的访问效果。但是在设置之后,再回到前台直接出现404找不到页面的请求提示。检查服务器,看到跟目录没有自动生成.htaccess文件,应该是不同的主机商不同的问题,有些时候会自动生成伪静态文件的。
顺带将这篇文章记录下来,将我们常用的WordPress建站过程中不同的系统Web环境伪静态规则和设置方法都记录下来,以便下次遇到的时候直接复制使用。一般而言,我们用的较多的是Apache/Nginx/IIS环境,可能第三种还用的不多,因为老蒋一直建议WP程序要在Linux系统中运行比较稳定。
文章目录 隐藏 第一、Apache伪静态规则和设置 第二、Nginx伪静态规则和设置 第三、IIS伪静态规则和设置第一、Apache伪静态规则和设置
# 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
我们将代码丢到sublime中,然后另存为.htaccess文件。然后FTP上传到网站根目录中即可,直接生效无需重启环境。
第二、Nginx伪静态规则和设置
location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
如果我们使用的Linux VPS主机,比如常规的一键包、WEB面板可能会自带WordPress Nginx伪静态文件,我们直接在添加站点的时候引用即可。如果就这么巧,且环境是自己编译安装的,没有Nginx伪静态规则,那我们就自己编辑后添加到当前站点的.conf文件中(server部分),或者单独创建一个WP规则(wordpress.conf),然后在配置文件中include调用。
第三、IIS伪静态规则和设置
老蒋也看到很多网友在Windows系统中搭建WP站点,可能是这帮朋友习惯和喜欢可视化的远程桌面。如果也有用到且缺少伪静态规则,那就用下面规则脚本。
?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>
保存为web.config,然后丢到网站根目录下,且需要检查服务器是否安装IIS URL Rewrite模块,如果没有则还需要去安装。
总结,如果我们不是特别的需要,建议如果安装和使用WordPress程序,还是在Linux系统中,用Nginx或者Apache,WordPress兼容也较好,设置也简单。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 常用WordPress伪静态规则 - Apache/Nginx/IIS系统环境
本文地址: https://pptw.com/jishu/667083.html
