wordpress不同服务器固定链接(伪静态)设置方法


我们都知道wordpress后台可以设置固定连接来优化我们网站的URL(当然可能你不知道,不知道请查看:wordpress固定链接使用教程),不过使用wordpress后台固定链接功能是需要我们服务器后台配置的,目前主流的服务器有Apache,Nginx,IIS。下面我们就来看下不同服务器如何设置wordpress的伪静态从而使wordpress的后台固定链接生效。
本文以”文章ID.html”为例
wjt

1、Apache .htaccess文件设置wordpress伪静态

apache设置wordpress伪静态我们可以在网站的更目录下建立.htaccess文件来实现,在.htaccess添加如下代码(无需重启服务器):

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. RewriteBase /
  4. RewriteCond %{REQUEST_FILENAME} !-f
  5. RewriteCond %{REQUEST_FILENAME} !-d
  6. RewriteRule . /index.php [L]
  7. </IfModule>

2、Nginx下WordPress的Rewrite

下面以本站的nginx配置为例,修改后需要重新reload nginx的配置

#找到server_name localhost;在后边一行添加上面的代码

  1. location /
  2. {
  3. try_files $uri $uri/ /index.php?q=$uri&$args;
  4. }

以本站为例:

  1. server {
  2. listen 80;
  3. server_name shouce.ren www.shouce.ren;
  4. root /data/wwwroot/54ux;
  5. #配置wordpress伪静态
  6. location / {
  7. try_files $uri $uri/ /index.php?q=$uri&$args;
  8. }
  9. if ($host != 'www.shouce.ren' ) {
  10. rewrite ^/(.*)$ http://www.shouce.ren/$1 permanent;
  11. }
  12.  
  13. if (!-e $request_filename) {
  14. rewrite (.*) /index.php last;
  15. }
  16. #php执行socket,根据自己情况定制
  17. include server.conf;
  18. }
  19.  

Windows+IIS系统wordpress伪静态配置

Windows+IIS系统的配置如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <system.webServer>
  4. <rewrite>
  5. <rules>
  6. <rule name="wordpress" patternSyntax="Wildcard">
  7. <match url="*"/>
  8. <conditions>
  9. <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
  10. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
  11. </conditions>
  12. <action type="Rewrite" url="index.php"/>
  13. </rule>
  14. </rules>
  15. </rewrite>
  16. </system.webServer>
  17. </configuration>