WordPress在多种服务器上的固定链接(伪静态)配置
我们都知道wordpress后台可以设置固定连接来优化我们网站的URL,不过使用wordpress后台固定链接功能是需要我们服务器后台配置的,目前主流的服务器有Apache,Nginx,IIS。下面我们就来看下不同服务器如何设置wordpress的伪静态从而使wordpress的后台固定链接生效。本文以”文章ID.html”为例:
1、Apache .htaccess文件设置wordpress伪静态
apache设置wordpress伪静态我们可以在网站的更目录下建立.htaccess文件来实现,在.htaccess添加如下代码(无需重启服务器):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
2、Nginx下WordPress的Rewrite
下面以本站的nginx配置为例,修改后需要重新reload nginx的配置
#找到server_name localhost;在后边一行添加上面的代码
<pre>
location /
{
try_files $uri $uri/ /index.php?q=$uri&$args;
}
3、Windows+IIS系统wordpress伪静态配置
Windows+IIS系统的配置如下:
<pre>
<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”wordpress” patternSyntax=”Wildcard”>
<match url=”*”/>
<conditions>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true”/>
<add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true”/>
</conditions>
<action type=”Rewrite” url=”index.php”/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
</pre>