@ 2010年08月13日

mod_rewrite 将大写路径重写成小写路径

一个同事今天提到的一个问题,将凡是包含大写字母的路径都通过 301 HTTP 头重定向到小写字母的路径,通过 Apache 的 mod_rewrite 可以达到目的,这里使用了 RewriteMap 的内部映射函数 int:tolower,请查看 http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_rewrite.html#RewriteMap

RewriteBase /
RewriteMap lowercase int:tolower
RewriteRule .*[A-Z].* ${lowercase:$0} [L,R=301]

貌似 RewriteMap 不能写到 .htaccess 内,会提示以下错误,只能放到配置文件了,如果有更好的解决方案,请联系我啦 :D

.htaccess: RewriteMap not allowed here

@ 2010年08月07日

Mac OS X 编译 sphinx 的一问题解决办法

昨天研究了一下 sphinx,回家在 Mac OS X 下用同样的方式编译 sphinx 时发生错误,

svn export http://sphinxsearch.googlecode.com/svn/trunk sphinx
cd sphinx
./configure --prefix=/usr/local/sphinx --with-mysql
make
...
sphinxstd.cpp: In function ‘bool sphIsLtLib()’:
sphinxstd.cpp:1001: error: ‘_CS_GNU_LIBPTHREAD_VERSION’ was not declared in this scope
make[2]: *** [sphinxstd.o] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1

最终在 sphinx 的 bug list 下找到该问题的解决办法 (bug #515)。

...

@ 2010年08月07日

Mac OS X 命令行配置 Alias

Mac OS X 的 Terminal profile 在控制台启动时加载,路径是 /etc/profile (for everyone) 和 ~/.profile (for 当前 user),编辑此文件,即可在每次启动控制台时生效,例如:

alias ls='ls -G'
alias grep='grep --color=auto'

@ 2010年08月05日

标题中文转换成英文文件名

因为要考虑到 SEO,今天按需求给项目写了个简单的函数,把文章标题和商品标题转换成英文文件名,

转换规则是:

中文中文 => Zhong-Wen-Zhong-Wen
中文chinese => Zhong-Wen-Chinese
chinese chinese => Chinese-Chinese

© 2011 Bun Wong

本博客基于 Bun PHP Framework 构建 • 粤ICP备07036370号