WordPress伪静态难倒了不少萌新,我刚刚入WordPress时,就为这个折腾了10多天,为了在搜索引擎之前设置好,这可急死了一些人,如果你看到了这个,那么你可能不那么麻烦了,我列出了4个主流Web服务器程序的伪静态规则!!!

 

Nginx伪静态:

try_files $uri $uri/ /index.php?$args;

没错,就是这么简单 完整:

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

 

Apache和Kangle:这两个程序都可以用.htaccess伪静态,所以我列举了3个规则,可以覆盖两个程序

普通:

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

多站点(子文件夹):

RewriteEngine On

RewriteBase /


RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

多站点(子域名):

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

把上面3个任选一个放入一个txt文件,然后上传,在服务器上改名为.htaccess放入网站根目录

IIS伪静态规则:

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

[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 条评论

今天头条 · 六月 28, 2018 12:17 上午

文章不错非常喜欢

    未来的小金鱼 · 六月 28, 2018 12:23 上午

    谢支持

发表评论

电子邮件地址不会被公开。 必填项已用*标注