301跳转中特殊要求的设置方法
首先说明一下,由于发展需要《爱回味》访问域名变更,近期将启动网站改版。
301跳转,一般是用来网站域名更换处理。本次处理需要做到两点,一:主域名 www.lovehw.com 直接跳转至lovehw.com
二、其他直接301至support.lovehw.com
解决方法:
www.lovehw.com htaccess 设置跳转至index.php
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
index.php 中判断来路网址是否有后面参数,有参数的直接跳转至support.lovehw.com 没有参数的跳转至主域名下:lovehw.com
代码如下:
$the_host = $_SERVER['HTTP_HOST'];//取得当前域名 $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//echo $request_uri;//die;//判断地址后面是否有参数 if($the_host == 'www.lovehw.com')//把这里的域名换上你想要的 { if($request_uri){ header('HTTP/1.1 301 Moved Permanently');//发出301头部 header('Location:http://support.lovehw.com'.$request_uri);//跳转到你希望的地址格式}else{ header('HTTP/1.1 301 Moved Permanently');//发出301头部 header('Location:http://lovehw.com');//跳转到你希望的地址格式 }}

301跳转中特殊要求的设置方法标题图片