301 redirect on bludit

User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

1dtravel wrote: Thu Apr 13, 2023 7:18 am This is a paid feature on the hosting.
You are right this is a paid feature. And it cannot turned off with .htaccess.

As a workaround you can manually modify the file site.php in the directory /bl-content/databases.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
1dtravel
Ssr. Bludit
Posts: 22
Joined: Sun Apr 09, 2023 5:12 pm

can you tell me in more detail which elements to fix in the file site.php so that there are no such errors with protection?
affiliate
Ssr. Bludit
Posts: 14
Joined: Mon Jul 04, 2022 1:25 pm
Been thanked: 2 times

Hi !
I was faced with a similat issue as you.

My hosting did https to http automatically, but not www to non www. So my site was accessible on both adresses.
To fix this, first i had to make corrections on the canonical plug in that was not working as it should be ( i posted the code in the forum ).
With this plugin at least if i had https://www.mysite.com, it displayed https://mysite.com in the canonical so even if the site was accessible on www, google knew which one to index. But of course, we should also redirect browser.

So, i tried to make this redirect from www to non www.
1) First, i tried to use the plugin redirect but it does not work with the last Bludit release (blank screen of death).

2) Then i tried to do it with .htaccess but for some reason it was not always working, maybe some problem with my hosting that is already doing some redirect.

3) Then i tought to do it with php and it worked. It s not very elegant but it works...

Here is how to do it.
You need to modify the index.php on top of the theme you are using.

So if you are using the Andy theme, you will go to bl-themes/andy/index.php
We need to modify this file because redirect must be done before any data is sent from the server.

On top of index.php you need to include the following like this

Code: Select all

<?php
// protocol : http ou https ?
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') $urlBrowser = "https://"; else $urlBrowser = "http://";
// host (domain name or ip adress)
$urlBrowser .= $_SERVER['HTTP_HOST'];
// ressource
$urlBrowser .= $_SERVER['REQUEST_URI'];

//display url of browser if you need
//echo $urlBrowser;

//possible redirects for
//http->https
//www -> non www

//for me : sometimes url will look like https://www.mysite.com/blog I want to redirect to https://mysite.com/blog
$findme   = '://www.';

$pos = strpos($urlBrowser, $findme);

if ($pos !== false) {
	//found need to redirect
	$urlBrowserNew = str_replace("://www.","://",$urlBrowser);
	//echo "I need to redirect to $urlBrowserNew";
	header("Status: 301 Moved Permanently");
	header('Location: '.$urlBrowserNew);
}

$findme   = 'http://';

$pos = strpos($urlBrowser, $findme);

if ($pos !== false) {
	//found need to redirect
	$urlBrowserNew = str_replace("http://","https://",$urlBrowser);
	//echo "I need to redirect to $urlBrowserNew";
	header("Status: 301 Moved Permanently");
	header('Location: '.$urlBrowserNew);
}

?>
<!doctype html>
<html lang="<?php echo Theme::lang() ?>">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
i also included http to https for you.
Post Reply