WordPress 伪静态规则设置方法

Admin
Admin
Admin
52
文章
6
评论
2018年3月2日09:41:30 评论 9,873 1721字阅读5分44秒

众所周知 WordPress 默认的链接是动态链接,虽然现在搜索引擎对动态的链接也有着非常好的收录,但是基于链接的美观,以及伪静态对搜索引擎更加有好的原因,我们还是非常希望能够将我们的 WordPress 设置成为伪静态方式,那么今天我们就来总结一下 Nginx Apache IIS 三种环境下的伪静态规则。

一、主机检测

检测主机是否支持伪静态的方法很简单:在WP后台 > 设置 > 固定链接,设置为 非默认带?的那种结构(我这边使用的是 /%postname%.html,你可以自己选择其他形式),然后访问任何一篇文章,如果出现 404 错误,说明你的主机当前不支持 WordPress 伪静态。

二、Nginx 伪静态规则

找到你的 Nginx 的conf配置文件,在 location / { } 中添加下面的代码,然后重启 Nginx 服务

  1. if (-f $request_filename/index.html){
  2.     rewrite (.*) $1/index.html break;
  3. }
  4. if (-f $request_filename/index.php){
  5.     rewrite (.*) $1/index.php;
  6. }
  7. if (!-f $request_filename){
  8.     rewrite (.*) /index.php;
  9. }

三、Apache 伪静态规则

在你的网站根目录中找到 .htaccess 文件,在最后加上以下的一条规则,然后重启 Apache 服务

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. RewriteBase /
  4. RewriteRule ^index\.php$ - [L]
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteRule . /index.php [L]
  8. </IfModule>

四、IIS伪静态规则

在你的网站根目录中找到 httpd.ini 文件,在最后加上以下的一条规则,然后重启 Apache 服务

  1. [ISAPI_Rewrite]
  2. # Defend your computer from some worm attacks
  3. #RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]
  4. # 3600 = 1 hour
  5. CacheClockRate 3600
  6. RepeatLimit 32
  7. # Protect httpd.ini and httpd.parse.errors files
  8. # from accessing through HTTP
  9. # Rules to ensure that normal content gets through
  10. RewriteRule /tag/(.*) /index\.php\?tag=$1
  11. RewriteRule /software-files/(.*) /software-files/$1 [L]
  12. RewriteRule /images/(.*) /images/$1 [L]
  13. RewriteRule /sitemap.xml /sitemap.xml [L]
  14. RewriteRule /favicon.ico /favicon.ico [L]
  15. # For file-based wordpress content (i.e. theme), admin, etc.
  16. RewriteRule /wp-(.*) /wp-$1 [L]
  17. # For normal wordpress content, via index.php
  18. RewriteRule ^/$ /index.php [L]
  19. RewriteRule /(.*) /index.php/$1 [L]

建议:不推荐在 Windows 的IIS服务器下安装 WordPress,因为 IIS 环境运行php程序的效率,相对同等配置下 Linux 的 Apache 和 Nginx 环境要低的多,更多的推荐使用 Nginx 服务器。

博主只是一名前端的小白,只是把自己用到的知识分享一下,要是有什么不对的地方,欢迎大家提出~~

继续阅读
Admin
  • 本文由 发表于 2018年3月2日09:41:30
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
移除 SourceTree 无用的远程分支 资源分享

移除 SourceTree 无用的远程分支

在开发过程中我们很多时候都需要将当前分支推送到远程仓库,该分支完成其使命之后再将其删除。 使用 SourceTree 的同学可能会发现 SourceTree 追踪的远端分支越来越多,许多已经删除的分支...
Linux 服务器修改 ssh 默认 22 端口方法 资源分享

Linux 服务器修改 ssh 默认 22 端口方法

博主在之前腾讯云有活动的时候,花了300多大洋撸了一台三年时间的 1H2G 入门级服务器,当时每次用 Shell 工具连接的时候都是感觉连接速度特别慢,等连接上后会有一个提示 “There were ...
常见 HTTP 状态码的理解 资源分享

常见 HTTP 状态码的理解

当浏览者访问一个网页时,浏览者的浏览器会向网页所在服务器发出请求,当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含 HTTP 状态码的信息头(server header)用以响应浏览器的请求...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: