当网址没有https或网址中有www时,我在FB应用上收到错误。我只想剥去www的网址。
下面的代码会添加https,如果它不在网址中,但我将如何删除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");
}
答案 0 :(得分:1)
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");
}
最简单的方法。
答案 1 :(得分:1)
尝试使用.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
答案 2 :(得分:1)
以下是使用.htaccess
与https
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteEngine
... On
https
是否为on
或www