如何设置WordPress的伪静态规则
WordPress伪静态规则设置方法如下: 1. 登录WordPress后台,进入“设置”菜单。 2. 选择“固定链接”,点击“自定义结构”。 3. 在“自定义结构”中输入您想要的URL格式,例如:`/%category%/%post_id%.html`。 4. 点击“保存更改”。 这样,您的WordPress网站就成功设置了伪静态规则。这种规则可以使您的URL更加简洁、易于记忆和SEO优化。如果您需要进一步了解如何设置WordPress伪静态规则,可以参考这篇文章。
根据服务器主机空间环境,只需加入下列伪静态规则即可。
Apache伪静态规则
新建一个 txt 文件,将下面的代码添加到文件中,然后另存为.htaccess文件,上传到WordPress站点的根目录即可。
1 | <IfModulemod_rewrite.c>RewriteEngineOnRewriteBase/RewriteRule^index.php$-[L]RewriteCond%{REQUEST_FILENAME}!-fRewriteCond%{REQUEST_FILENAME}!-dRewriteRule./index.php[L]</IfModule> |
Nginx伪静态规则
在Nginx中的server模块配置如下内容,打开 nginx.conf 或者某个站点的配置环境,例如 /usr/local/nginx/conf/yzipi.conf,在server{ } 大括号里面添加下面的代码。
1 | location/{ if (-f $request_filename /index.html){rewrite(.*) $1 /index.htmlbreak;} if (-f $request_filename /index.php){rewrite(.*) $1 /index.php;} if (!-f $request_filename ){IIS伪静态规则rewrite(.*)/index.php;}} |
IIS伪静态规则
新建一个 txt 文件,将下面的代码添加到文件中,然后另存为 httpd.ini 文件,上传到WordPress站点的根目录即可。
1 | [ISAPI_Rewrite]#Defendyourcomputerfromsomewormattacks#RewriteRule.*(?: global .asa| default .ida|root.exe|..).*.[F,I,O]#3600=1hourCacheClockRate3600RepeatLimit32#Protecthttpd.iniandhttpd.parse.errorsfiles#fromaccessingthroughHTTP#RulestoensurethatnormalcontentgetsthroughRewriteRule/tag/(.*)/index.php?tag= $1RewriteRule /software-files/(.*)/software-files/ $1 [L]RewriteRule/images/(.*)/images/ $1 [L]RewriteRule/sitemap.xml/sitemap.xml[L]RewriteRule/favicon.ico/favicon.ico[L]#Forfile-basedwordpresscontent(i.e.theme),admin,etc.RewriteRule/wp-(.*)/wp- $1 [L]#Fornormalwordpresscontent,viaindex.phpRewriteRule^/$/index.php[L]RewriteRule/(.*)/index.php/ $1 [L] |