1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php强制用户转向www域名办法

php强制用户转向www域名办法

时间:2020-08-17 15:23:56

相关推荐

php强制用户转向www域名办法

php教程|php手册

php,强制,转向,www域名

php教程-php手册

webgis 源码,vscode调试scanf,ubuntu锁定,tomcat 支持跳转,sqlite3存放blob,啦啦外卖跑腿源码短信接口插件,微擎前端是基于什么框架,屏幕爬虫子整蛊视频,php 扩展编译安装,商城市seo优化,手机赌博澳门网站源码,html网页特效返回顶部,公司简介模板轴承lzw

这篇文章主要介绍了php强制用户转向www域名的方法,可实现模拟301重定向的功能,并且针对无法head重定向的情况输出链接,需要的朋友可以参考下

网站源码广告怎么找出来,ubuntu源码编译pcl,网页js动态爬虫,rpmbuild php,seo办公软件lzw

博彩软件源码,ubuntu的定时服务,tomcat启动过后404,阻止 蜘蛛 爬虫,php 安装 libpng,河北什么是seo关键词优化策略lzw

有时候网站的www域名和非www域名都能访问网站,但是这样不利于搜索引擎的收录,会分散网页的权重,所以希望用户访问非www的域名时通过301永久重定向到www域名,例如用户访问会直接转向,本php代码考虑了无法通过head重定向的情况,会在页面上输出链接,,让用户点击。

// Install info.:

// Copy and paste these lines into your default index.php or

// the file that get’s called if a visitor comes on your

// website…

// read the host from the server environment

$host = $_SERVER[“HTTP_HOST”];

// fix host name – we never now… ????

$host = strtolower($host);

$host = trim($host);

// This is important:

// Webbrowsers like Firefox are doing their request without

// the port number like “” but some other

// applications send host names like “:80”

$host = str_replace(‘:80’, ”, $host);

$host = trim($host);

// if the host is not starting with redirect the

// user to the same URL but with www ????

if ($host != ‘’){

// You an also change the “!=” to “==”, if you want to force

// the user to use the domain name without the

// send status header, so that search engines or other services

// detect that this is a permanent redirect and not a temporary

header(‘HTTP/1.1 301 Moved Permanently’);

// read the URL the user requested:

$url = isset($_SERVER[“REQUEST_URI”]) ? $_SERVER[“REQUEST_URI”] : ”;

// redirect the user to the new destination:

header(‘Location: ‘ . $url);

// Convert “special” chars — cause we never now… ????

$url = htmlspecialchars($url);

// “fallback” link, if the browser is not supporting header redirects

print ‘Please click here’;

// stop the script execution here

exit;

}

// If the domain is then go on with your PHP code

// of with your website…

// BTW: You need to replace trough your own domain ????

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。