zoukankan      html  css  js  c++  java
  • wordpress 在linux上配置固定url方法

    wordpress 设置固定url总结

    相信好多用wordpress的网友为了提升wordpress对搜索引擎的友好,或者是为了写的博客地址更好记,都会在wordpress的后台设置固定url的方式。

    但问题来了,一开始wordpress默认的url是用域名加?p=id的方式的。改了后就出来404页面

    我们来百度下吧,不知道就搜索呀,得到结果如下

    通过在Apache配置文件httpd.conf中找到LoadModule rewrite_module modules/mod_rewrite.so  将其前面的注释#去掉,然后重启服务器,问题就解决了。

    下面说下在nginx下的设置,在nginx的网站配置文件中加入下面的代码

    location / {
    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;
            }
    }

    但是我的服务器上的nginx有一个默认wordpress的规则文件(这个文件不保证所有nginx下都能用,自己测试吧)

    wordpress.conf

    location /blog/ {
            try_files $uri $uri/ /blog/index.php?$args;
    }
    
    # Add trailing slash to */wp-admin requests.
    rewrite /blog/wp-admin$ $scheme://$host$uri/ permanent;

    在nginx的网站配置文件中将这个wordpress.conf引入

    如 /usr/local/nginx/conf/vhost/blog.conf

    blog.conf就是我的nginx上的网站配置文件

    这个文件中加入

    include wordpress.conf;

    重启lnmp现在还是404

    问题出在,我是以wordpress作为根目录而wordpress的规则应该是按照根目录下的/blog文件夹这样的网站配置路径来写的

    所以wordpress.conf应该改为

    location / {
            try_files $uri $uri/ /index.php?$args;
    }
    
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    再重启服务,问题解决

  • 相关阅读:
    elasticsearch安装kibana插件
    elasticsearch安装head插件
    elasticsearch分别在windows和linux系统安装
    oracle赋某表truncate权限
    mysql 事件(Event) 总结
    MySQL存储过程入门教程
    MYSQL数据库重点:自定义函数、存储过程、触发器、事件、视图
    MySQL外键使用详解
    Mysql视图使用总结
    mysql导出指定字段或指定数据到文件中
  • 原文地址:https://www.cnblogs.com/IssacQQ/p/4269007.html
Copyright © 2011-2022 走看看