简体   繁体   English

服务器/ Apache从1.3升级到2.0强制HTTPS和WWW时出现错误

[英]Server/Apache upgrade from 1.3 to 2.0 gives me an error when forcing HTTPS and WWW

My hosting company emailed me yesterday to tell me that they are upgrading Apache... so this morning I found my site down and not working. 我的托管公司昨天向我发送电子邮件,通知我他们正在升级Apache ...因此今天早上,我发现我的网站无法正常运行。

The problem was that the browser was giving me "This webpage has a redirect loop" error. 问题是浏览器给我“此网页有重定向循环”错误。 The hosting company don't want to help however after some investigating I've located the code which is breaking the site. 托管公司不想帮忙,但是经过一番调查,我找到了破坏站点的代码。

I need to force SSL (https) and the www subdomain of the site... the following code used to do this but now it is giving me headaches... can anyone help me amend this as everything I have tried hasn't worked? 我需要强制使用SSL(https)和网站的www子域...以下代码用于执行此操作,但现在它让我头疼...任何人都可以帮我修改此内容,因为我尝试过的所有方法均无效? The following code is put in an include so each page of the site forces (or redirects the user to use https and www in the domain). 以下代码放在一个include中,因此该网站的每个页面都会强制执行(或重定向用户以在域中使用https和www)。

//force the subdoman and https://...
if($_SERVER["HTTP_HOST"] != 'www.mysite.co.uk'){
    header('HTTP/1.1 301 Moved Permanently');
    $forceurl = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : '';
    header('Location: https://www.mysite.co.uk' . $forceurl);
    die();
}


if ($_SERVER['HTTPS'] != 1){
    $newurl2 = "https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; 
    header("location: $newurl2");
    die();
}

Okay I managed to solve all of this... 好吧,我设法解决了所有这些问题。

I completely removed the code above and replaced it within the .htaccess like so... 我完全删除了上面的代码,并将其替换为.htaccess中的代码,如下所示...

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.myurl\.co\.uk [NC]
RewriteRule ^(.*)$ https://www.myurl.co.uk/$1 [R=301,L] 
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I then noticed a problem with the payment API I use wasn't working with the site, I kept getting the following message when trying to make a purchase/payment, "The HTTP method received is not valid. Only POST is accepted". 然后,我注意到我使用的付款API不适用于该站点,尝试进行购买/付款时,我不断收到以下消息,“收到的HTTP方法无效。仅接受POST”。 This was odd as I was using POST! 当我使用POST时,这很奇怪! The following helped me solve that issue.. 以下内容帮助我解决了这个问题。

The HTTP method received is not valid. 收到的HTTP方法无效。 Only POST is accepted 仅接受POST

PLEASE NOTE THAT MY HOSTING PROVIDER DID NOT COVER THIS IN THEIR UPGRADE GUIDE/DOCUMENTATION! 请注意,我的托管服务提供商未在其升级指南/文档中对此进行说明! I will be communicating this to my good friends at 1and1! 我将在1and1与我的好朋友交流!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM