location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
阿里云为您提供 Nginx 设置 wordpress 伪静态的方法,但是官方描述并不详细,阿里云的共享虚拟主机,由于服务器是 Nginx,原有的 Apache 的伪静态规则就不适用了,因此折腾伪静态规则用了不少时间,为了避免其他人走冤枉路就分享这个教程。
Nginx 的阿里云(万网)虚拟主机是有伪静态配置的地方的,它不需要上传伪静态规则,只需要在主机控制界面设置下,然后重启下站点就可以了,具体的位置如下图:
在这里填写如下的伪静态规则就可以了
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
设置完伪静态规则后,记得重启虚拟主机,在主机信息那里,先点下停止,再点击下启动即可。这样就设置好了,网站的内页不会出现 404 错误了。
WordPress 安装在 IIS/Apache/Nginx 服务器对应伪静态规则
[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]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Nginx伪静态规则
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
专业提供WordPress主题安装、深度汉化、加速优化等各类网站建设服务,详询在线客服!