当前位置:首页文章笔记建站教程WordPress 伪静态规则(IIS/Apache/Nginx)设置方法

WordPress 伪静态规则(IIS/Apache/Nginx)设置方法

今天总结一下 IIS/Apache/Nginx 三种环境下的伪静态规则,希望对大家有所帮助。检测主机是否支持伪静态的方法:在 WP 后台 > 设置 > 固定链接,设置为 非默认带?的那种结构,然后访问任何一篇文章,如果出现 404 错误,说明你的主机当前不支持 WordPress 伪静态。
WordPress 伪静态规则(IIS/Apache/Nginx)设置方法

IIS 伪静态规则

IIS 环境是 Windows 主机常用的服务器环境,新建一个 txt 文件,将下面的代码添加到文件中:

  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]

然后另存为 httpd.ini 文件,上传到 WordPress 站点的根目录即可。

Apache 伪静态规则

Apache 是 Linux 主机下常见的环境,现在一般的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面的代码:

  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>

然后上传到 WordPress 站点的根目录,重命名为 .htaccess 即可

Nginx 伪静态规则

Nginx 环境一般是 Linux 主机 VPS 或服务器用户用的比较多,这些用户一般都会自己配置 Nginx,或者有专门的人帮你配置,打开 nginx.conf 或者某个站点的配置环境,比如 wpdaxue.com.conf(不同人配置的不一样),在 server { } 大括号里面添加下面的代码:

  1. location / {
  2. try_files $uri $uri/ /index.php?$args;
  3. }
  4. # Add trailing slash to */wp-admin requests.
  5. rewrite /wp-admin$ $scheme://$host$uri/ permanent;

保存,重启 Nginx 即可。

注:如果以上规则不适用,请自己查看 WP 官方文档:https://codex.wordpress.org/Nginx

温馨提示:

文章标题:WordPress 伪静态规则(IIS/Apache/Nginx)设置方法

文章链接:https://www.wuyanshuo.cn/760.html

更新时间:2022年04月20日

本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:service@wuyanshuo.cn我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读无言说网络服务协议

给TA打赏
共{{data.count}}人
人已打赏
建站教程

WordPress 限制搜索关键词实现搜索黑名单

2022-4-20 11:00:34

建站教程

更改WordPress编辑器中“在此输入标题”占位符提示文字

2022-4-21 11:00:48

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
'