php从网址中删除www [英] php removing www from url

查看:87
本文介绍了php从网址中删除www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当URL没有https或URL中有www时,我在FB应用程序上遇到错误.我只是要去掉www的网址.

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. I am just going to strip the url of the www.

如果下面的代码不在网址中,则下面的代码添加https,但我也将如何删除www ?

The code below adds the https if it is not in the url but how would I remove the www as well?

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");
}

最简单的方法.

这篇关于php从网址中删除www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆