首页 > SEO优化 > wordpress伪静态规则大全,内含IIS/Apache/Nginx三种环境教程

wordpress伪静态规则大全,内含IIS/Apache/Nginx三种环境教程

时间:2023年10月19日 分类:SEO优化 浏览量:64

问题缘由

因为wordpress默认的链接样式不好看,且不美观,没有一个完好的目录结构展示

解决思路

我们可以通过wordpress后台的设置-固定连接来进行设置,例图:

除了默认外的其他设置均可以改变wordpress默认的链接结构,但是设置这一块是需要我们的主机支持的;检测主机是否支持的最好办法就是,选择一个除默认外的其他样式,保存,然后随便点击一个文章看是否出现404,如果出现,那么很抱歉了,您的主机现在还不支持wordpress伪静态!

到了这一步,我们就需要了解我们所使用的主机是什么环境的了,这个问题,我们可以问空间服务商得到答案,通常是IIS/Apache/Nginx这三种环境,而下面将分别给出这三个环境的伪静态规则!

IIS伪静态规则

IIS 环境是 Windows 主机常用的服务器环境,新建一个 txt 文件,将下面的代码添加到文件中:

  1. [ISAPI_Rewrite]

  2. # Defend your computer from some worm attacks

  3. #RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]

  4. # 3600 = 1 hour

  5. CacheClockRate 3600

  6. RepeatLimit 32

  7. # Protect httpd.ini and httpd.parse.errors files

  8. # from accessing through HTTP

  9. # Rules to ensure that normal content gets through

  10. RewriteRule /tag/(.*) /index\.php\?tag=$1

  11. RewriteRule /software-files/(.*) /software-files/$1 [L]

  12. RewriteRule /images/(.*) /images/$1 [L]

  13. RewriteRule /sitemap.xml /sitemap.xml [L]

  14. RewriteRule /favicon.ico /favicon.ico [L]

  15. # For file-based wordpress content (i.e. theme), admin, etc.

  16. RewriteRule /wp-(.*) /wp-$1 [L]

  17. # For normal wordpress content, via index.php

  18. RewriteRule ^/$ /index.php [L]

  19. RewriteRule /(.*) /index.php/$1 [L]

然后另存为 httpd.ini 文件,上传到WordPress站点的根目录即可。

Apache伪静态规则

Apache是 Linux 主机下常见的环境,现在一般的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面的代码:

  1. <IfModule mod_rewrite.c>

  2. RewriteEngine On

  3. RewriteBase /

  4. RewriteRule ^index\.php$ – [L]

  5. RewriteCond %{REQUEST_FILENAME} !-f

  6. RewriteCond %{REQUEST_FILENAME} !-d

  7. RewriteRule . /index.php [L]

  8. </IfModule>

然后上传到 WordPress 站点的根目录,重命名为 .htaccess 即可

Nginx伪静态规则

Nginx环境一般是Linux 主机 VPS或服务器用户用的比较多,这些用户一般都会自己配置Nginx,或者有专门的人帮你配置,打开 nginx.conf 或者某个站点的配置环境,比如 2zzt.com.conf(不同人配置的不一样),在  server   { } 大括号里面添加下面的代码:

  1. location / {

  2. if (-f $request_filename/index.html){

  3.                 rewrite (.*) $1/index.html break;

  4.         }

  5. if (-f $request_filename/index.php){

  6.                 rewrite (.*) $1/index.php;

  7.         }

  8. if (!-f $request_filename){

  9.                 rewrite (.*) /index.php;

  10.         }

  11. }

保存,重启 Nginx 即可。

当然,小2建议大家使用wordpress来搭建网站的时候还是选择linux的空间比较好,因为linux下的Apache 和 Nginx 环境还比win下的 IIS 运行php程序的效率要高的多!

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

标签: