Nginx伪静态规则,优化SEO并美化URL

兰科勒布劳恩斯基
2025-07-20 / 0 评论 / 151 阅读 / 正在检测是否收录...

Nginx
想必大家看到一个长的url栏,都会非常烦躁,这种url栏不仅不美观而且还长,不易于记忆和搜索引擎索引,进而影响搜索引擎排名。
做伪静态的效果如下,去除index.php

未配置伪静态 https://www.xmlans.com/index.php/1.html
配置伪静态 https://www.xmlans.com/1.html

大家也看到了,去掉烦人的index能让网站内文章不那么深入目录,优化搜索引擎的索引,并且将加上index.php的网页自动重定向回短的url,这就是伪静态的最佳实践,不仅美化缩短了url,还优化了搜索引擎索引,因为往往搜索引擎不希望层层嵌套的网站
将文本写入nginx.conf文件中,重启Nginx即可实现伪静态
下面就给大家Nginx伪静态规则:

  1. typecho (本博客使用的系统)

     if (!-e $request_filename) {
         rewrite ^(.*)$ /index.php$1 last;
     }
  2. WordPress

    location /
    {
      try_files $uri $uri/ /index.php?$args;
    }
    
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
  3. Discuz 论坛社区

    location / {
             rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
             rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
             rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
             rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
             rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
         }
  4. PHPCMS

    location / {
     ###PHPCMS
     rewrite ^(.*)show-([0-9]+)-([0-9]+)\.html$ $1/show.php?itemid=$2&page=$3;
     rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/list.php?catid=$2&page=$3;
     rewrite ^(.*)show-([0-9]+)\.html$ $1/show.php?specialid=$2;
     ####PHPWind
     rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
     rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
    }
  5. Z-Blog 博客系统

    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;
    }
  6. ShopWind

    location / {
      #Redirect everything that isn't a real file to index.php
      try_files $uri $uri/ /index.php$is_args$args;
    }
    #If you want a single domain name at the front and back ends
    location /admin {
      try_files $uri $uri/ /admin/index.php$is_args$args;
    }
    location /mobile {
      try_files $uri $uri/ /mobile/index.php$is_args$args;
    }
    location /api {
      try_files $uri $uri/ /api/index.php$is_args$args;
    }
0

评论 (0)

取消