内容 |
做seo的大家都知道,网址的首选域要统一非常重要。也就是比如网站绑定了两个域名,包括带www的和不带www的,那么要选择一个作为主要域名做推广,那么就需要将另外一个域名301跳转到主域名。 如果服务器支持,比如是iis7以上的服务器的话,可以使用web.config的301跳转代码。使用linux操作系统的可以使用.htaccess的301跳转。 那么phpwind的论坛,想要将不带www的跳转到www的域名,还可以使用php代码做301跳转。 phpwind论坛的页面都调用的一个文件是global.php,经过测试将下面一段代码放入global.php可以实现整个论坛的301跳转(我将http://aaa.com/跳转到http://www.aaa.com/): $the_floor = $_server['http_host']; $floor_pageurl=str_replace(.php?, -htm-, $_server[request_uri]); //因为做了伪静态所以将网址中的.php?替换成-htm- if($floor_pageurl == '/index.php') //如果是首页的话,将网址设为空。 { $floor_pageurl='/'; } if($the_floor == '16floor.com') { header('http/1.1 301 moved permanently'); header('location:http://www.16floor.com'.$floor_pageurl); } 将上面这段代码放到global.php文件这段代码下面就可以了: file_exists('install.php') && header('location: ./install.php'); error_reporting(e_error | e_parse); set_magic_quotes_runtime(0); function_exists('date_default_timezone_set') && date_default_timezone_set('etc/gmt+0');
|