云朵镇 發表於 2023-9-12 00:00:00

Wordpress固定链接伪静态的设置方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
今天,想着在我机器上测试一下wordpress,虽然之前也有这个开源的程序,可是一直没有安装呢,再加上最近一直忙于其他的工作,也忽略了不少,突然想建立一个属于自己的博客,我想记录一些生活中的点点滴滴以及爱好之类的。于是今天就在我本地测试了一下,大家都知道对于搜索引擎来讲,静态页面比较好收录一些,可是我从wordpress的后台设置了固定链接,可是总是显示找不到页面,</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
wordpress固定链接设置参数: 参数不多说,很死的东西,按照WordPress官方文档列表如下:<br>
1. %year% 基于文章发布年份,比如2007;<br>
2. %monthnum% 基于文章发布月份,比如05;<br>
3. %day% 基于文章发布当日,比如28;<br>
4. %hour% 基于文章发布小时数,比如15;<br>
5. %minute% 基于文章发布分钟数,比如43<br>
6. %second% 基于文章发布秒数,比如33<br>
7. %postname% 基于文章的postname,其值为撰写时指定的缩略名,不指定缩略名时是文章标题;<br>
8. %post_id% 基于文章post_id,比如423;<br>
9. %category% 基于文章分类,子分类会处理成“分类/子分类”这种形式;<br>
10. %author% 基于文章作者名。<br>
将上述参数进行组合,即可得到wordpress的固定链接形式。网上常见的几种设置方法:<br>
/%year%/%monthnum%/%day%/%postname%/<br>
/%year%/%monthnum%/%postname%/<br>
/%year%/%monthnum%/%day%/%postname%.html<br>
/%year%/%monthnum%/%postname%.html<br>
/%category%/%postname%.html<br>
/%category%/%post_id%<br>
/%postname%.html<br>
/%post_id%.html 我们一般使用这个方式比较好。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
wp永久链接设置技巧:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
一、不要让日期出现在wordpress固定链接里面<br>
这基于两个方面的考虑。一是如果数字出现在固定链接里面,等于提醒搜索引擎,这是很旧的内容了,没必要再爬一遍了。另外一个原因是,假如你要修改文章的日期重新发布的话,链接地址就变了,也就是意味着你的反向链接,PR 等等都没有了。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
二、不要让分类的链接出现在固定链接里面</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
这一点是很多人都会忽略的地方。让分类出现在固定链接里面有两个缺陷:一是一篇文章如果选择了多个分类的话,则会出现多个链接地址,这很容易造成因为重复内容而被搜索引擎惩罚;二是有可能会造成关键词堆砌而被搜索引擎惩罚。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
三、链接不要过深</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
这一点经常看到。很多wordpress 用户的固定链接是年/月/日/分类名/文章名。这种过于深的固定链接对搜索引擎是非常不友好的。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
四、不要让中文字符出现在固定链接里面</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
虽然现在的搜索引擎已经能识别URL地址里面的中文字符,但无论是从美观上,还是从wordpress 优化的角度来看,都是非常差的。<br>
Win服务器下设置WordPress固定链接伪静态<br>
只要主机支持自定义404页面,无需安装插件,就能让Win主机像Linux 那样,方便使用WordPress的固定链接为静态化地址格式。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
设置固定链接(Permalink)伪静态步骤:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
1. 将以上代码保存为 404.php,并上传至主机根目录。<br>
2. 设置 404 自定义错误页为 404.php。<br>
3.进入 WordPress 控制面板,设置(Options)- WordPress固定链接(Permalinks),选择固定链接格式。如果你觉得上面新建404页面太麻烦了!那我给你推荐一个插件吧!那就是 Permalinks Migration Plugin Permalinks Migration Plugin的主要原理是利用“301转向”来实现既不丢失原有的链接,同时又让读者和搜索引擎知道,你已经修改了固定链接的效果,让他们尽快更新链接。 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
也许自己好久没有写程序了,慢慢的什么都给退化了呢,我也有看见wordpress写有.htaccess这个文件,为什么不行呢?后来上网查了一下,原来我未开启伪静态的模块LoadModule rewrite_module,于是在 apache的配置文件httpd.conf开启了LoadModule rewrite_module,然后再设置固定链接的形式为/%post_id%.html,就可以打开了,自然高兴了,我本地的环境是win+php+apache的;当然为我们提供的服务商一般用的iis服务器的,解决办法是</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
首先你先问你空间商,你购买的空间支持不支持伪静态,一般购买的付费空间/虚拟主机都是支持的。如果支持的话,就创建一个httpd.ini文件,把下面代码保存到该文件中,上传到网站的根目录就可以了。然后,之后进入WP后台修改固定链接,比如修改为:%/tegory%/%post_id%.html,很简单吧。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div id="phpcode1" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
<br>
# Defend your computer from some worm attacks<br>
#RewriteRule .*(?:global.asa|default.ida|root.exe|..).* . <br>
# 3600 = 1 hour&lt;/p&gt; &lt;p&gt;CacheClockRate 3600<br>
RepeatLimit 32&lt;/p&gt; &lt;p&gt;# Protect httpd.ini and httpd.parse.errors files<br>
# from accessing through HTTP<br>
# Rules to ensure that normal content gets through&lt;/p&gt; &lt;p&gt;RewriteRule /tag/(.*) /index.php?tag=$1<br>
RewriteRule /software-files/(.*) /software-files/$1 <br>
RewriteRule /images/(.*) /images/$1 <br>
RewriteRule /sitemap.xml /sitemap.xml <br>
RewriteRule /favicon.ico /favicon.ico <br>
# For file-based wordpress content (i.e. theme), admin, etc.<br>
RewriteRule /wp-(.*) /wp-$1 <br>
# For normal wordpress content, via index.php<br>
RewriteRule ^/$ /index.php <br>
RewriteRule /(.*) /index.php/$1 </div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
这个规则文件的写法是IIS6.0下最新的wordpress伪静态规则。一般win主机都是IIS6.0的web服务器 ,而不是Apache的,在IIS服务器下,像一些常见的wordpress博客、shopex网店系统等第三方知名第三方程序,伪静态的实现,自己只需要把网站的静态化规则文件命名为httpd.ini文件放在网站根目录就可以了,无须通过网站后台设置,那是在Linux系统下的Apache服务器下才那样设置。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
下面这个方法也是从网上找来的,希望和大家一起分享学习了,有什么好的方法一起多多交流了!</p>
頁: [1]
查看完整版本: Wordpress固定链接伪静态的设置方法