[英]php removing www from url
I am getting an error on a FB app when the url does not have the https or and has a www in the url. 当URL没有https或URL中有www时,我在FB应用程序上遇到错误。 I am just going to strip the url of the www.
我只是要剥离www的网址。
The code below adds the https if it is not in the url but how would I remove the www as well ? 下面的代码添加了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");
}
easiest way. 最简单的方法。
Try to do it using .htaccess 尝试使用.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
Here is a way to do it with your .htaccess
with https
这是通过
https
.htaccess
一种方法
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteEngine
... On
RewriteEngine
...... On
https
is ... on
or https
是否在... on
或 www
www
开头
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.