Forum

Thread tagged as: Question, Problem

use perch_page_url in template force https://

Hi,

I use this code to get the right link for a menu. The problem is that a get http and not https so i get a 301 error. Is there a way to force https?

I set define('PERCH_SSL', true); then i get a ERR_TOO_MANY_REDIRECTS error

            <?php       
                PerchSystem::set_var('var_url', perch_page_url([], true));
                perch_content_custom('Facts_land', [
                    'template'=>'facts_land.html'
                ]);
            ?>  
Fleur Besters

Fleur Besters 0 points

  • 3 years ago

Hello

Add this to your htaccess

# force www.
   RewriteCond %{HTTP_HOST} !^www\. [NC]
   RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force https
   RewriteCond %{HTTP:X-Forwarded-Proto} !https 
   RewriteCond %{HTTPS} off
   RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Thx,

That is not the problem. I al ready done that. The problem is that de link from the template is not https:// When i click on the url .htacces change it to https:// The problem is that it give a 301 error. I want a https:// url for the menu at https://www.reisbijbel.nl/marokko See klimaat.

I hope you understand me.

master page code

<?php       
                PerchSystem::set_var('var_url', perch_page_url([], true));
                perch_content_custom('Facts_land', [
                    'template'=>'facts_land.html'
                ]);
            ?>  

Template code

        <div class="label noaction" itemprop="name"><a itemprop="url" href="<perch:content id="var_url" type="hidden" />/klimaat">klimaat</a></div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't recommend using the PERCH_SSL stuff any more. It was designed for a time when people had mixed http and https environments. These days everything should be https.

Drew McLellan said:

I don't recommend using the PERCH_SSL stuff any more. It was designed for a time when people had mixed http and https environments. These days everything should be https.

Thx Drew, I use https:// for the site. The problem is that when i use

<?php       
                PerchSystem::set_var('var_url', perch_page_url([], true));
                perch_content_custom('Facts_land', [
                    'template'=>'facts_land.html'
                ]);
            ?>  

I get a https:// url back in place of a https://

Where can i change that?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's using the value of the HTTPS header on the request to determine if the URL should be http or https.

In PHP terms, it's checking $_SERVER['HTTPS']