Linux下给WordPress配置伪静态

  WordPress是一个被广泛使用的Blog系统,由于它的强大,甚至在建设网站的时候也可以用到。而其支持伪静态(Wordpress Permalinks)的功能更被津津乐道。在使用LAMP平台的时候,开启Wordpress的伪静态是很容易的,而在zeus下,却出了一些小麻烦,记录如下:

  环境:
  ZWS 4.3r3 FreeBSD i386 6.1-RELEASE
  WordPress 2.0.4(现在最新版是2.5.1)

  启用 htaccess Support

  启用后,却发现只能让wordpress 实现下面的链接方式:

  /index.php/yyyy/mm/dd/post-name/

  而我想实现的,是这样的链接方式:
  /yyyy/mm/dd/post-name/

  查询了一下wordpress 文档,需要apache mod_rewrite 支持才能实现这种链接方式。

  启用 Request Rewriting

  在Rewrite Script输入以下代码:
RULE_0_START:
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}

# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
RULE_0_END:

RULE_1_START:
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}

# check to see if the file requested is an actual file or
# a directory with possibly an index. don’t rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then
set URL = /index.php?q=%{SCRATCH:REQUEST_URI}
goto QSA_RULE_START
endif
endif

# if we made it here then its a file or dir and no rewrite
goto END
RULE_1_END:

QSA_RULE_START:
# append the query string if there was one originally
# the same as [QSA,L] for apache
match SCRATCH:ORIG_URL into % with \?(.*)$
if matched then
set URL = %{URL}&%{SCRATCH:QUERY_STRING}
endif
goto END
QSA_RULE_END:

  随后,回到 WordPress Permalinks 进行相应的设置,一切正常,问题解决。

linux

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyspzz.html