初识wordpress网站的朋友都了解静态化url的重要性,就算不懂得什么叫伪静态,也懂得文章后台的链接应该是*.html不应该是一个问号后面加一个数字。其实wordpress实现伪静态很容易。但是对于不同服务器环境配置下的朋友设置wordpress伪静态规则还是有一定难度的。
当前主流的主机很少自带wordpress伪静态功能,除非是专业的wordpress主机;当然这里没有广告,还没有遇到过一款自带伪静态的主机哈哈;先说下固定链接的设置方法;
登录到你的WordPress网站后台,设置 – 固定链接 – 选择自定义结构选项;推荐使用以下形式
域名/分类别名/文章ID.html
/%category%/%post_id%.html
如果你对这种形式不满意,可以自定义任意形式,只要合理搭配参数即可,可以使用的参数如下:
%year%:文章发表的年份,四位数字,如2012
%monthnum%:文章发表的月份,如08
%day%:文章发表的日期,如28
%hour%:文章发表的时间(小时),如15
%minute%:文章发表的时间(分钟),如18
%second%:文章发表的时间(秒),如28
%postname%:文章别名,在发表文章时可以设置。
%post_id%:文章的ID,如68
%category%:分类别名,在添加分类时可以设置。
%tag%:标签的别名,在添加标签时可以设置。
下面我说来讲讲针对于不同主机几种伪静态规则;
Linux 主机环境
先在本地创建一个txt 文件,添加下面的代码:然后上传到 WordPress 站点的根目录,重命名为 .htaccess ;注意在本地是无法创建.htaccess因为文件格式是非法的;
area data-settings="dblclick" readonly ><IfModule mod_rewrite.c>RewriteEngine OnRewritebase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule>area>12345678<IfModule mod_rewrite.c>RewriteEngine OnRewriteba
se /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule>
Windows 主机环境
同l主机一样,首先需要创建一个 txt 文件,然后将下面的代码添加到文件中:直接另存为 httpd.ini 文件,上传到WordPress站点的根目录即可
area data-settings="dblclick" readonly >[ISAPI_Rewrite]# Defend your computer from some worm attacks#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]# 3600 = 1 hourCacheClockRate 3600RepeatLimit 32 # Protect httpd.ini and httpd.parse.errors files# from accessing through HTTP# Rules to ensure that normal content gets throughRewriteRule /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]# For file-based wordpress content (i.e. theme), admin, etc.RewriteRule /wp-(.*) /wp-$1 [L]# For normal wordpress content, via index.phpRewriteRule ^/$ /index.php [L]RewriteRule /(.*) /index.php/$1 [L]area>16171819202122[ISAPI_Rewrite]# Defend your computer from some worm attacks#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]# 3600 = 1 hourCacheClockRate 3600RepeatLimit 32 # Protect httpd.ini and httpd.parse.errors files# from accessing through HTTP# Rules to ensure that normal co
ntent gets throughRewriteRule /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]# For file-ba
sed wordpress co
ntent (i.e. theme), admin, etc.RewriteRule /wp-(.*) /wp-$1 [L]# For normal wordpress content, via index.phpRewriteRule ^/$ /index.php [L]RewriteRule /(.*) /index.php/$1 [L]
不推荐在 windows 的IIS服务器下安装 WordPress,因为 IIS 环境运行php程序的效率低对php兼容度不够。对于php环境的程序Linux永远是最佳的解决方案