WordPress不同服务器固定链接(伪静态)设置方法
我们都知道wordpress后台可以设置固定连接来优化我们网站的URL(当然可能你不知道,不知道请查看:wor…
我们都知道wordpress后台可以设置固定连接来优化我们网站的URL(当然可能你不知道,不知道请查看:wordpress固定链接使用教程),不过使用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;在后边一行添加上面的代码
location /
{
try_files $uri $uri/ /index.php?q=$uri&$args;
}
以本站为例:
server {
listen 80;
server_name shouce.ren www.shouce.ren;
root /data/wwwroot/54ux;
#配置wordpress伪静态
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
if ($host != 'www.shouce.ren' ) {
rewrite ^/(.*)$ http://www.shouce.ren/$1 permanent;
}
if (!-e $request_filename) {
rewrite (.*) /index.php last;
}
#php执行socket,根据自己情况定制
include server.conf;
}
Windows+IIS系统wordpress伪静态配置
Windows+IIS系统的配置如下:
<?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>
类别:WordPress入门、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论功能已经关闭!