域名跳转html
参数: Apache mod_rewrite 规则重写 1) R[=code](force redirect) 强制外部重定向 说明:强制在替代字符串加上http://thishost[:thisport]/前缀重定向到外部的URL.若是code不指定,将用缺省的302 HTTP状态码。 2) F(force URL to be forbidden)禁用URL,返回403HTTP状态码。 3) G(force URL to be gone) 强制URL为GONE,返回410HTTP状态码。 4) P(force proxy) 强制使用代理转发。 5) L(last rule) 代表当前规则是最后一条规则,中止分析之后规则的重写。 6) N(next round) 从新从第一条规则开始运行重写过程。 7) C(chained with next rule) 与下一条规则关联 8) T=MIME-type(force MIME type) 强制MIME类型 9) NS (used only if no internal sub-request) 只用于不是内部子请求 10) NC(no case) 不区分大小写 11) QSA(query string append) 追加请求字符串 12) NE(no URI escaping of output) 不在输出转义特殊字符 说明:RewriteRule /foo/(.*) /bar?arg=P1%3d$1 [R,NE] 将能正确的将/foo/zoo转换成/bar?arg=P1=zoo 13) PT(pass through to next handler) 传递给下一个处理 说明:RewriteRule ^/abc(.*) /def$1 [PT] # 将会交给/def规则处理Alias /def /ghi 14) S=num(skip next rule(s)) 跳过num条规则 15) E=VAR:VAL(set environment variable) 设置环境变量 16) OR 表明或者 注:若是规则匹配则正常处理,8)之后的标志无效,若是不匹配,那么下面全部关联的规则都跳过。
格式: # 调用mod_rewrite.c模块 <IfModule mod_rewrite.c> # 打开rewirte功能 RewriteEngine on # 声明Client请求的主机中前缀不是www.client.cn RewriteCond %(HTTP_HOST) ^www.client.com$ # 含义是若是Client请求的主机中的前缀符合上述条件,则直接跳转。 AuthType Basic ^(.*)$ http://www.server.com/$1 [R=301,L] </IfModule>
实例配置正则表达式
命令:apache2/bin/apachectl -M | grep rewrit rewrite_module (shared) 若是不存在:
# 编辑主配置文件,解注释 vim httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so 注:若是没有该模块,则须要经过apxs工具安装模块。
二、修改虚拟主机配置文件apache
vim httpd-vhosts.conf # 1对1域名跳转 <VirtualHost *:80> DocumentRoot "/usr/local/html" ServerName www.server.com ServerAlias www.aaa.com <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www.aaa.com$ RewriteRule ^/(.*)$ http://www.server.com/$1 [R=301,L] </IfModule> <Directory /usr/local/html> require all granted </Directory> </VirtualHost> # 1对多域名跳转 <VirtualHost *:80> DocumentRoot "/usr/local/html" ServerName www.server.com ServerAlias www.aaa.com ServerAlias www.bbb.com <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR] RewriteCond %{HTTP_HOST} ^www.bbb.com$ RewriteRule ^/(.*)$ http://www.server.com/$1 [R=301,L] </IfModule> <Directory /usr/local/html> require all granted </Directory> </VirtualHost>
注:跳转状态码 301表明永久重定向 302临时重定向 注:$1表明地址后跟的网络文件。 注:访问一个“/”能够输入如下格式。 RewriteCond %(HTTP_HOST) 456.com RewriteRule /(.*)$ HTTP://123.com/$1 [R=301,L]
三、从新读取配置文件vim
apache2/bin/apachectl graceful