宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

云主机或vps推荐使用宝塔面板搭建服务器环境,内置了wordpress伪静态规则,直接选择即可,使用十分简单。

以下给大家分享nginx,apache,iis下的wordpress伪静态规则

Nginx 伪静态规则
打开 nginx.conf 或者某个站点的配置环境,比如 fengjunzi.com.conf(不同人配置的不一样),在 server { } 大括号里面添加下面的代码:

[php]location / {
if -f $request_filename/index.html){
rewrite .*) $1/index.html break;
}
if -f $request_filename/index.php){
rewrite .*) $1/index.php;
}
if !-f $request_filename){
rewrite .*) /index.php;
}
}

[/php]

保存,重启 Nginx 即可。

Apache 伪静态规则
新建一个 htaccess.txt 文件,添加下面的代码:

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

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

IIS 伪静态规则
新建一个 txt 文件,将下面的代码添加到文件中:

[php]

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

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

本文转自:https://www.ewuxiu.com/3330.html