Wordpress设置更改固定链接,访问出现 404 错误。
标题内容
1.基于Lnmp(Lnamp)环境(https://lnmp.org),配置文件目录为 /usr/local/nginx/conf/vhost 。
2.domain.com 指的是解析后的域名,这里修改为自己的。
Nginx
1.最简单的方法(推荐),就是在添加虚拟主机的时候在 Allow Rewrite rule? (y/n)
,选择 wordpress
。如果添加虚拟主机的时候没有选择,之后可以到配置文件自己添加一行 include rewrite/wordpress.conf;
然后重启即可。
Allow Rewrite rule? (y/n) y Please enter the rewrite of programme, wordpress,discuzx,typecho,thinkphp,laravel,codeigniter,yii2 rewrite was exist. (Default rewrite: other): wordpress You choose rewrite: wordpress |
2.或者也可以自己手动对配置文件进行修改。附完整配置文件(添加以下深色标记代码重启Nginx即可)。
虚拟主机配置文件
# Upstream to abstract backend connection(s) for php upstream php { server unix:/tmp/php-cgi.socket; server 127.0.0.1:9000; } server { listen 80; #listen [::]:80; server_name domain.com ; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/domain.com; include none.conf; include enable-php.conf; location / { # This is cool because no php is touched for static content. # include the "?$args" part so non-default permalinks doesn't # break when using query string try_files $uri $uri/ /index.php?$args; } location ~ .php$ { include fastcgi.conf; fastcgi_intercept_errors on; fastcgi_pass php; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log off; } |
Apache
若Lamp 或者 Lnamp环境,在网站根目录新建 .htaccess
文件即可(如果该文件存在,则不必新建)。
# 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 |