您的位置 首页 php

建站技术:WordPress伪静态规则


伪静态是把动态的网页伪造为静态的页面。如 youranzixue.com/?p=38 中带有问号,这种称为动态链接,可以通过伪静态设置把网站修改为 youranzixue.com/38.html。没有问号的页面我们可以称为静态页面。

当用户访问 38.html 这个网页时,地址栏保持不变,程序实际是去请求了?p=38页面显示出来。这样的重写由服务器上的伪静态重写组件完成。目前大部分主机都支持伪静态设置。

不同的 WEB服务器 设置伪静态规则的方式不一样。

IIS

不同的IIS版本使用不同的方式设置伪静态规则,如httpd.ini.web.config等文件方式。不建议使用IIS安装 WordPress 程序。

httpd.ini方式

 [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 /software-files/(.*) /software-files/$1 [L]
RewriteRule /images/(.*) /images/$1 [L]
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]  

web.config方式

 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web server >
<rewrite>
<rules>
<rule name="ChineseURL" stopProcessing="true">
<match url="^(tag|category)/(.*)$" />
<action type="Rewrite" url="chineseurl.php"/>
</rule>
<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>  

APACHE

Apache方式是在网站根目录下面创建一个 . htaccess 文件。在文件里面添加伪静态规则即可。

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

nginx

Nginx环境一般是Linux 主机 VPS或服务器用户用的比较多,这些用户一般都会自己配置Nginx,或者有专门的人帮你配置,打开 nginx.conf 或者某个站点的配置环境,比如 wpdaxue.com.conf(不同人配置的不一样),在 server { } 大括号里面添加下面的代码:

 location /
{
	 try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;  

宝塔面板

目前国内使用宝塔面板的用户比较多,宝塔设置伪静态规则比较简单,后台->网站->设置->伪静态->选择WordPress就行了。

工具:宝塔提供的 Apache与Nginx伪静态规则互转。

文章来源:智云一二三科技

文章标题:建站技术:WordPress伪静态规则

文章地址:https://www.zhihuclub.com/153141.shtml

关于作者: 智云科技

热门文章

网站地图