htaccess 的一点用法

LAMP 环境里可以很容易的通过 .HTACCESS 进行一些网站的设置
网站引索:

DirectoryIndex index.php index.htm index.html

域名重定向,将yaoyingying.com 重定向到 www.yaoyingying.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yaoyingying\.com$ [NC]
RewriteRule ^(.*)$ http://www.yaoyingying.com/$1 [R=301,L]

下面这些对静态页网站的 URL 优化就有很大帮组了,取好每个页面文件的名字,通过 下面的规则进行目录结构式优化。

RewriteRule ^([a-z]+)\/([a-z0-9]+)-([a-z0-9]+)\/$            $1_$2-$3.php   [QSA,L]
RewriteRule ^([a-z]+)\/([a-z]+)-([a-z]+)\/$            $1_$2-$3.php   [QSA,L]
RewriteRule ^([a-z]+)\/([a-z]+)-([a-z]+)-([a-z]+)\/$            $1_$2-$3-$4.php   [QSA,L]
RewriteRule ^([a-z]+)-([a-z]+)\/([a-z]+)\/$            $1-$2_$3.php   [QSA,L]
RewriteRule ^([a-z]+)-([a-z]+)\/([a-z]+)-([a-z]+)\/$   $1-$2_$3-$4.php   [QSA,L]
RewriteRule ^([a-z]+)-([a-z]+)\/([a-z]+)-([a-z]+)-([a-z]+)\/$   $1-$2_$3-$4-$5.php   [QSA,L]

RewriteRule ^([a-z]+)\/([a-z0-9]+)\/$            $1_$2.php  [QSA,L]
RewriteRule ^(.*)\/$                            $1.php   [QSA,L]