WordPress怎么实现伪静态

2025-11-21 05:25:13

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

[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 /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]   # For normal wordpress content, via index.php   RewriteRule ^/$ /index.php [L]   RewriteRule /(.*) /index.php/$1 [L]

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

2、Apache是 Linux 主机下常见的环境,新建一个 htaccess.txt 文件,添加下面的代码:

<IfModule mod_rewrite.c>   RewriteEngine On   RewriteBase /   RewriteRule ^index\.php$ - [L]   RewriteCond %{REQUEST_FILENAME} !-f   RewriteCond %{REQUEST_FILENAME} !-d   RewriteRule . /index.php [L]   </IfModule>

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

3、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 即可。

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢