WordPress伪静态规则设置(迁移网站需要重写规则)

1、IIS的Wordpress伪静态规则配置
创建httpd.ini 文件,将以下内容粘贴到文件中,然后上传到WordPress站点的根目录即可。


[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]

2、Nginx的Wordpress伪静态规则配置
在Nginx的虚拟主机配置文件中,在 server { } 大括号里面,加入以下代码:


location / {
try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

保存,重启 Nginx 即可。

3、Apache的Wordpress伪静态规则配置
编辑httpd.conf(在那里? APACHE目录的CONF目录里面)

查找

Options FollowSymLinks
AllowOverride None

改为
Options FollowSymLinks
AllowOverride All

如果已经开启了htaccess,则直接进入下一步:

新建一个 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 即可

发表评论