wordpress固定链接的wordpress固定链接的结构

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wordpress固定链接的wordpress固定链接的结构相关的知识,希望对你有一定的参考价值。

参考技术A

这里有几个结构可以作为参考:
%year% 日志发表的年份,四位数字
%monthnum% 日志发表的月份
%day% 日志发表的日期
%hour% 日志发表的时间-小时
%minute% 日志发表的时间-分钟
%second% 日志发表的时间-秒
%postname%日志标题的缩略版本(日志/页面编辑界面上的日志别名)。因此“This Is A Great Post!”在URI中会变成this-is-a-great-post。
%post_id%日志的唯一ID,如123
%category%分类名称的缩略版本(添加新分类/编辑界面上的分类别名)。嵌套的子分类会作为嵌套子目录出现在URI中。出于运行方面的考虑,不推荐以%category%作为固定链接的起始部分。
%tag%标签名称的缩略版本(添加新标签/编辑界面上的标签别名)。出于运行方面的考虑,不推荐以%tag%作为固定链接的起始部分。
%author%作者名称的缩略版本.
既然知道了我们就可以对这些开始组合了。
几种组合方式如下
/?p=%post_id%(默认的)
/%year%/%monthnum%/%day%/%postname%/(年/月/日/日志名)
/%year%/%monthnum%/%postname%/(年/月/日志名)
/%monthnum%/%day%/%postname%/(月/日/日志名)
/%year%/%monthnum%/%day%/%post_id%/(年/月/日/日志id号)
/%year%/%monthnum%/%post_id%/(年/月/日志id号)
/%monthnum%/%day%/%post_id%/(月/日/日志id号)
/archives/%post_id%(/archives/日志id号)
/archives/%postname%(/archives/日志名)
/%post_id%(/日志id号)
/%postname%(/日志名)
/%category%/%postname%.html (分类/日志名.html)
/%category%/%postname%.htm(分类/日志名.htm)
/%postname%.html(/日志名.html)
/%postname%.htm(/日志名.htm)
/%post_id%.html(/日志id号.html)
/%post_id%.htm(/日志id号.htm)
常用的就是以htm后者html方式结尾的。当然这个可以随你的喜好自由改变。
win主机IIS 6 WordPress固定连接的设置
一般使用wordpress都会将设置固定链接(伪静态),这样更有利于seo,wordpress在LINUX系统的服务器中可以很好的使用,在Windows主机,为了完美支持伪静态就需要下点功夫。
空间需要支持rewrite组件,现在几乎所有WIN主机都支持Rewrite 组件,有个问题就是,博客链接能伪静态,可中文标签的链接打不开,比如我们设置的中文目录中文tag,就打不开了。解决WordPress博客伪静态中文标签无法打开可以使用下面的规则:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
RewriteRule /tag/(.*) /index\\.php\\?tag=$1
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
RewriteRule /robots.txt /robots.txt [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]
在使用上有什么不清楚请查看下面的参考资料,有详细的设置教程 很多朋友主站并不想放博客,有的朋友喜欢美观想放一个主页什么的,有的是公司的网站,或者有的朋友想做淘宝客,那么这样只能把WordPress放到二级目录(子目录)里面了,wordpress在二级目录的伪静态规则规则:
[ISAPI_Rewrite]
# 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 /blog/sitemap.xml /blog/sitemap.xml [L]
RewriteRule /blog/favicon.ico /blog/favicon.ico [L]
# For tag
RewriteRule /blog/tag/(.*)/page/(\\d+)$ /blog/index\\.php\\?tag=$1&paged=$2
RewriteRule /blog/tag/(.+)$ /blog/index\\.php\\?tag=$1
# For category
RewriteRule /blog/category/(.*)/page/(\\d+)$ /blog/index\\.php\\?category_name=$1&paged=$2
RewriteRule /blog/category/(.*) /blog/index\\.php\\?category_name=$1
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /blog/wp-(.*) /blog/wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/blog/$ /blog/index.php [L]
RewriteRule /blog/(.*) /blog/index.php/$1 [L]
#For page
RewriteRule /blog/page/(.*)/?s=(.*) /blog/index\\.php\\?s=$2&paged=$1
RewriteRule /blog/page/(.*) /blog/index\\.php\\?paged=$1
如果在规则使用上有什么不明白的地方请查看下面的参考资料详细教程 如果根目录和子目录同时装wordpress程序,该怎么实现伪静态?
固定链接设置规则:
[ISAPI_Rewrite]  # 3600 = 1 hour  CacheClockRate 3600  RepeatLimit 32  # For sub  RewriteRule /wordpress/sitemap.xml /wordpress/sitemap.xml [L]  RewriteRule /wordpress/favicon.ico /wordpress/favicon.ico [L]  RewriteRule /wordpress/tag/(.*)/page/(\\d+)$ /wordpress/index\\.php\\?tag=$1&paged=$2  RewriteRule /wordpress/tag/(.+)$ /wordpress/index\\.php\\?tag=$1  RewriteRule /wordpress/category/(.*)/page/(\\d+)$ /wordpress/index\\.php\\?category_name=$1&paged=$2  RewriteRule /wordpress/category/(.*) /wordpress/index\\.php\\?category_name=$1  RewriteRule /wordpress/wp-(.*) /wordpress/wp-$1 [L]  RewriteRule ^/wordpress/$ /wordpress/index.php [L]  RewriteRule /wordpress/(.*) /wordpress/index.php/$1 [L]  RewriteRule /wordpress/page/(.*)/?s=(.*) /wordpress/index\\.php\\?s=$2&paged=$1  RewriteRule /wordpress/page/(.*) /wordpress/index\\.php\\?paged=$1  # For root  RewriteRule /tag/(.*) /index\\.php\\?tag=$1  RewriteRule /robots.txt /robots.txt [L]  RewriteRule /sitemap.xml /sitemap.xml [L]  RewriteRule /favicon.ico /favicon.ico [L]  RewriteRule /wp-(.*) /wp-$1 [L]  RewriteRule /wordpress/(.*) /wordpress/$1 [L]  RewriteRule ^/$ /index.php [L]  RewriteRule /(.*) /index.php/$1 [L]
关于规则使用设置,详细图文教程请查看下面的参考资料
win主机IIS 7 WordPress固定连接的设置
“美观的”固定链接通常会要求使用mod_rewrite,而IIS(常见于Windows服务器)却不支持mod_rewrite。(如果你在Windows上使用Apache 2.0.54,mod_rewrite可能会运行,前提是要在apache\\conf\\httpd.conf.中激活mod_rewrite)。
使用IIS 7并具备服务器管理权限时,可以使用Microsoft的URL重写模块来代替mod_rewrite。虽然IIS 7不完全兼容mod_rewrite,但它支持WordPress的固定链接。Microsoft的URL重写模块安装完毕后,在WordPress目录下打开web.config文件,将以下规则添加到system.webServer 元素中:
<rewrite>
< rules>
< rule name=Main Rule stopProcessing=true>
< match url=.* />
< conditions logicalGrouping=MatchAll>
< 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>
win主机 IIS 7伪静态规则的具体使用方法可以查看下面参考资料
IIS网站上有一份关于Microsoft的URL重写模块详细的安装指南,该模块可用于 x64 与x86系统。
如果这个方法行不通,还可以试试PATHINFO链接;将index.php/放在自定义链接结构的开始部分前:
/index.php/%year%/%monthnum%/%day%/%postname%/这个方法并不总能成功,尤其是用在运行于ISS 6上的WordPress时。要让这方法运行在IIS上,需要将以下两行代码添加到php.ini文件并将文件保存在网络根目录下。
cgi.fix_pathinfo = 1
cgi.force_redirect = 0
另一种解决方法是利用IIS的自定义404重定向。这要求你的虚拟主机允许你添加自定义404重定向,不过这并不需要你安装任何第三方mod_rewrite软件,也不需要你的固定链接结构以/index.php/开头。
IIS7虚拟主机装两个wordpress固定链接设置
安装两个wordpress,一个在根目录,一个在子目录(二级目录)伪静态规则设置方案:
根目录的伪静态规则设置可以看下面参考资料
在子目录(二级目录)中的安装wordpress,Web.config配置文件伪静态代码:
<?xml version=1.0 encoding=UTF-8?>
<configuration>
<system.webServer>
<rewrite>
<rules><remove name=wordpress/>
<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>
详细的设置方案,图文教程可查看下面参考资料

PHP WordPress使用固定链接和CSS拉出特色图像

// Add to functions.php theme support for Featured Images if your theme does not already include it.
if (function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails');
    add_image_size('index-categories', 150, 150, true);
    add_image_size('page-single', 575, 200, true);
}

Call image using timthumb from a page or post by adding to page.php, single.php, home.php or index.php.

 &lt;?php if (has_post_thumbnail( $post-&gt;ID )): ?&gt;
   &lt;?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post-&gt;ID ), 'full' );  ?&gt;
   &lt;img class=&quot;featuredImage&quot; src=&quot;&lt;?php bloginfo('template_directory'); ?&gt;/timthumb.php?src=&lt;?php echo $image[0]; ?&gt;&amp;w=576&amp;h=200&amp;zc=1&quot; alt=&quot;&lt;?php the_title(); ?&gt;&quot; /&gt;
&lt;?php endif; ?&gt;

CSS
Note: image tag has the class .featuredImage. Style as needed:
img.featuredImage{border: 2px solid #ccc;padding: 10px;}

以上是关于wordpress固定链接的wordpress固定链接的结构的主要内容,如果未能解决你的问题,请参考以下文章

wordpress固定链接的固定链接的类型

wordpress的固定链接怎么设置成数字.html

如何自定义wordpress文章的固定链接

如何自定义wordpress文章的固定链接

wordpress 固定链接错误

WordPress固定链接设置的几种方法