一些有用apache重写规则

# 将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]
Tags: apache, url_rewrite

相关日志

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

还没有评论。

发表评论

(必填)

(必填)


*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comment moderation is enabled. Your comment may take some time to appear.