欢迎光临
我们一直在努力
卡尔云 大网数据--高防低价服务器抢购 低至28/月十堰4-4就在零零陆云计算 金华高防物理机 40H64G 30M 158/月 819云计算香港20MCN2 300元/月
林枫云-专注独立IP高频VPS 低价高性价比—迅速云 GoDo云计算韩国物理机低至299元/月 龍行数据:美国100M服务器 299元/月 络V云计算:新加坡100M服务器 1200元/月
CNMCDN防护稳定又实惠 轻松云:美国200兆VPS16元/月 亦宁云200M大带宽 动态BGP低至35/月 低价高效上云-道之云网络 【科御云】香港CDN、延迟低速度快防御高

常用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兼容也较好,设置也简单。

赞(0)
未经允许不得转载:沃园 » 常用WordPress伪静态规则 – Apache/Nginx/IIS系统环境

评论 抢沙发

评论前必须登录!

立即登录   注册