一些有用apache重写规则

转载时请标明文章原始出处和作者信息, 作者: lostsnow.
http://www.lsproc.com/blog/useful_apache_urlrewrite/

# 将domain.com/xxx转向www.domain.com/xxx
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$  http://www.domain.com$1 [R=301,NC]

# 将xxx.domain.com/yyy...重定向到www.domain.com/xxx/yyy..., xxx 5-20位, 字母开头只含字母, 数字以及"-"和"_"
RewriteCond %{SERVER_NAME} ^([a-z][a-z0-9\-\_]{4,19})\.domain\.com [NC]
RewriteRule ^(.+)$ %{SERVER_NAME}$1 [C]
RewriteRule ^([a-z][a-z0-9\-\_]{4,19})\.domain\.com(.*)$ http://www.domain.com/$1$2 [R=301,NC]

# 将首页www.domain.com转向www.domain.com/html/index.html
RewriteCond %{HTTP_HOST} www\.domain\.com
RewriteRule ^/$  http://www.domain.com/html/index.html [R=301,L]

-- EOF --

Related Posts

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>