[英]php removing www from url
当URL没有https或URL中有www时,我在FB应用程序上遇到错误。 我只是要剥离www的网址。
下面的代码添加了https(如果它不在URL中),但是我也将如何删除www ?
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
$redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("HTTP/1.1 301 Moved Permanently");
header("Location: $redirect");
}
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
$redirect = str_replace('www.', '', "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
header("HTTP/1.1 301 Moved Permanently");
header("Location: $redirect");
}
最简单的方法。
尝试使用.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
这是通过https
.htaccess
一种方法
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteEngine
...... On
https
是否在... on
或 www
开头
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.