设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 教程 > 正文

WordPress操作固定链接伪静态

发布时间:2022-06-25 13:45 所属栏目:61 来源:互联网
导读:有点基础的人都知道静态URL有助于SEO,能够让搜索引擎更好的收录,并且现在好多主题的功能都是需要实现伪静态才能够使用的,相信大部分的人都是知道伪静态的重要性,WordPress要想实现伪静态也是非常简单的,但我发现还是有很多新人朋友都设置不好,下面小新就给大
  有点基础的人都知道静态URL有助于SEO,能够让搜索引擎更好的收录,并且现在好多主题的功能都是需要实现伪静态才能够使用的,相信大部分的人都是知道伪静态的重要性,WordPress要想实现伪静态也是非常简单的,但我发现还是有很多新人朋友都设置不好,下面小新就给大家讲解一下:
 
  固定链接其实就是修改 WordPress 目录、页面或者帖子的URL链接形式。固定链接不仅可以优化链接、保持链接的美观性使用户得到更好的体验,还可以更好的SEO优化,修改后的静态地址更容易让搜索引擎接受从而达到更好的排名。要想设置固定链接成功的话必须先添加伪静态规则。
 
  IIS伪静态规则
 
  新建一个txt文件,然后把下面的代码复制粘贴进去另存为 httpd.ini 文件,上传到网站根目录.
 
  [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] --phpfensi.com
  # For normal wordpress content, via index.php
  RewriteRule ^/$ /index.php [L]
  RewriteRule /(.*) /index.php/$1 [L]
  Apache伪静态规则
 
  新建一个 htaccess.txt 文件,把下面代码复制粘贴进去保存后上传到网站根目录,重命名为 .htaccess.
 
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  Nginx伪静态规则
 
  打开 nginx.conf 或者某个站点的配置环境,不同人配置的不一样,在 server { } 大括号里面添加下面的代码后保存,重启 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;
          }
  }
  一般的情况下大多数都是使用IIS+Apache,小新博客就是使用IIS和Apache实现伪静态的!Now!规则写好之后就可以固定链接了,固定链接之前先了解一下官方的一些结构参数:
 
  %year%:发布文章的年份,比如2010;
  
  %monthnum%:发布文章的月份,比如01;
  
  %y%:发布文章当日,比如06;
  
  %hour%:发布文章小时数,比如23;
  
  %minute%:发布文章分钟数,比如43;
  
  %second%:发布文章秒数,比如33;
  
  %postname%:文章的postname,文章的别名;
  
  %post_id%:文章的post_id,比如48;
  
  %tegory%:文章的分类;
  
  %author%:文章作者名。
  固定链接时应该注意什么呢?
 
  1、不要让日期出现在固定链接里面
 
  2、不要让分类的链接出现在固定链接里面
 
  3、链接不要太深
 
  4、链接中不要出现中文
 
  网上常见的链接格式:
 
  /%year%/%monthnum%/%y%/%postname%/
  
  /%year%/%monthnum%/%postname%/
  
  /%year%/%monthnum%/%y%/%postname%.html
  
  /%year%/%monthnum%/%postname%.html
  
  /%tegory%/%postname%.html
  
  /%post_id%.html
  
  /%postname%/
  固定链接设置:
 
  wordpress后台<设置<固定链接.
 
  小新用的是/%post_id%.html我觉得简洁美观,用户体验起来效果更好,推荐使用.

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读