WordPress 伪静态规则(IIS/Apache/Nginx)详细教程

2020年5月15日00:05:32825 1360字阅读4分32秒

1、IIS伪静态规则

[ISAPI_Rewrite]
# Defend your computer from some worm attacks
#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]
# 3600 = 1 hour

CacheClockRate 3600
RepeatLimit 32
 
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through

RewriteRule /tag/(.*) /index\.php\?tag=$1
RewriteRule /software-files/(.*) /software-files/$1 [L]
RewriteRule /images/(.*) /images/$1 [L]
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /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.php
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

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

2、Apache伪静态规则

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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

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

Nginx伪静态规则

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

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

保存,重启 Nginx 即可。

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

新手建站网
  • 本文由 发表于 2020年5月15日00:05:32
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
WordPress如何关闭自动更新? wordpress

WordPress如何关闭自动更新?

今天的我导航网突然后到一条“您的站点已被更新至WordPress 5.8 ”邮件,对于部分想自动更新的人来说确实省事了,但是像我们这种用了第三方主题的小伙伴来说万一更新不兼容处理起来就麻烦了,经过我查...
Wordpress水印插件推荐 wordpress

WordPress水印插件推荐

对于原创作者来说,强调图片版权,防止懒人直接盗图,给图片加上水印还是很必要的。以前我都是手动添加水印,不过我觉得能用插件解决的问题就不应该手动,所以经过我调查使用后推荐一款相对比较满意的插件:Easy...