名称:全站301重定向跳转教程
日期:2016-09-30
适用:所有服务器下的301重定向设置
以下使用域名chtml.cn做301重定向操作列子
dns域名解析设置301重定向[通用方式]:
将chtml.cn解析到主机ip地址,并同把www.chtml.cn的域名也解析到服务器的ip地址中。
记录类型选择"显性url";
解析记录选择“ @ ” ;
apache服务器301重定向:
1.在apahce的httpd.conf文件里面开启 mod_rewrite重写URL模块
2.然后在站点配置文件中加入以下代码:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^chtml.cn
RewriteRule ^(.*)$ http://www.chtml.cn/$1 [R=permanent,L]
nginx服务器301重定向
把 chtml.cn www.chtml.cn一同解析到服务器ip绑定后在站点配置文件中加入以下代码
server_name www.chtml.cn chtml.cn;
if ($host != 'www.chtml.cn' ) {
rewrite ^/(.*)$ http://www.chtml.cn/$1
permanent;
}
其他方法[apache使用,放在网站根目录]:
利用.htaccess设置301全站跳转
RewriteEngine On
RewriteCond %{HTTP_HOST} !^chtml.cn$ [NC]
RewriteRule ^(.*)$ http://chtml.cn/$1 [L,R=301]
TOMACT301重定向
1.把项目导出为name.war
2.然后放到tomcat的webapps目录下
3.修改tomcat/conf目录下的server.xml文件。
4.打开server.xml,找到host标签
5.将name修改成域名如:name=”www.chtml.cn” 再加上
<Context docBase="D:\Apache\Tomcat 8.0\webapps\name.war" path="/" reloadable="true"/>
端口改成80
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
完整示例
<Host name="www.chtml.cn" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context docBase="D:\Apache\Tomcat 8.0\webapps\name.war"
path="/" reloadable="true"/>
</Host>
注:依据自己的类型填写,docBase是项目name.war在tomcat的路径,注意是”\”而不是”/” 。