wordpress .htaccess 固定链接-WordPress更改固定链接404的解决办法

在WordPress网站建设中,固定链接设置是必不可少的。 好的固定链接更加美观、好用、有利于用户分享和搜索引擎收录。 需要注意的是,设置的固定链接生效的前提是你的网站环境支持伪静态

常用的参数包括

日期和名称类型/%year%/%monthnum%/%day%/%postname%/月份和名称类型/%year%/%monthnum%/%postname%/数字类型/archives/%post_id%帖子名称/%帖子名%/ID+html类型/%post_id%.html

很多站长在使用WordPress的时候可能会遇到一个问题。 他们想让 WordPress 伪静态。 后台设置固定链接后wordpress .htaccess 固定链接,文章页面或所有页面都会出现404错误。 下面提供在各种Web环境下设置WordPress伪静态规则的教程。

Apache伪静态规则

Apache是​​Linux主机下常见的环境,现在大多数Linux虚拟主机都使用这个环境。 创建一个新的 htaccess.txt 文件并添加以下代码:

wordpress .htaccess 固定链接_链接固定方式_链接固定Ip地址


RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

复制

然后上传到WordPress站点根目录并重命名为.htaccess。 修改完成后wordpress .htaccess 固定链接,必须重新启动Apache才能生效。

Nginx伪静态规则

打开nginx.conf或者某个站点的配置环境,如qq52o.me.conf(不同网站配置不同),在server{}大括号内添加以下代码:

location / {  
    index index.html index.php;   
    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;   
    }   
}   
  
rewrite /wp-admin$ $scheme://$host$uri/ permanent;  

复制

保存后,重启Nginx。

IIS伪静态

wordpress .htaccess 固定链接_链接固定Ip地址_链接固定方式

强烈不建议在Windows的IIS服务器下安装WordPress,因为在相同配置下,IIS环境下运行PHP程序的效率比Linux的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]

复制