
今天总结一下 IIS/Apache/Nginx 三种环境下的伪静态规则,希望对大家有所帮助。检测主机是否支持伪静态的方法:在WP后台 > 设置 > 固定链接,设置为 非默认带?的那种结构,然后访问任何一篇文章,如果出现 404 错误,说明你的主机当前不支持 wordpress 伪静态。
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站点的根目录即可。
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
总结以上是内存溢出为你收集整理的WordPress 伪静态规则(IIS/Apache/Nginx)设置方法全部内容,希望文章能够帮你解决WordPress 伪静态规则(IIS/Apache/Nginx)设置方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)