52杰奇论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 4509|回复: 0

WordPress 伪静态规则(IIS/Apache/Nginx)

[复制链接]

598

主题

251

回帖

100万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1004948
发表于 2022-4-23 16:00:00 | 显示全部楼层 |阅读模式
不少朋友总是询问 WordPress 如何添加伪静态规则,今天倡萌就总结一下 IIS/Apache/Nginx 三种环境下的伪静态规则,希望对大家有所帮助。
检测主机是否支持伪静态的方法:在WP后台 > 设置 > 固定链接,设置为 默认带?的那种结构,然后访问任何一篇文章,如果出现 404 错误,说明你的主机当前不支持 WordPress 伪静态。
IIS伪静态规则
IIS 环境是 Windows 主机常用的服务器环境,新建一个 txt 文件,将下面的代码添加到文件中:
12345678910111213141516171819202122
[ISAPI_Rewrite# Defend your computer from some worm attacks#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]# 3600 = 1 hourCacheClockRate 3600RepeatLimit 32 # Protect httpd.ini and httpd.parse.errors files# from accessing through HTTP# Rules to ensure that normal content gets throughRewriteRule /tag/(.*) /index\.php\?tag=$1RewriteRule /software-files/(.*) /software-files/$1 [LRewriteRule /images/(.*) /images/$1 [LRewriteRule /sitemap.xml /sitemap.xml [LRewriteRule /favicon.ico /favicon.ico [L# For file-based wordpress content (i.e. theme), admin, etc.RewriteRule /wp-(.*) /wp-$1 [L# For normal wordpress content, via index.phpRewriteRule ^/$ /index.php [LRewriteRule /(.*) /index.php/$1 [L

然后另存为 httpd.ini 文件,上传到WordPress站点的根目录即可。
Apache伪静态规则
Apache是 Linux 主机下常见的环境,现在一般的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面的代码:
12345678
<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [LRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L</IfModule>

然后上传到 WordPress 站点的根目录,重命名为 .htaccess 即可
Nginx伪静态规则
Nginx环境一般是Linux 主机 VPS或服务器用户用的比较多,这些用户一般都会自己配置Nginx,或者有专门的人帮你配置,打开 nginx.conf 或者某个站点的配置环境,比如 wpdaxue.com.conf(不同人配置的不一样),在  server   { } 大括号里面添加下面的代码:
123456
location / {        try_files $uri $uri/ /index.php?$args;} # Add trailing slash to */wp-admin requests.rewrite /wp-admin$ $scheme://$host$uri/ permanent;

保存,重启 Nginx 即可。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|52杰奇论坛  

GMT+8, 2024-4-29 12:32 , Processed in 0.113850 second(s), 27 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表