https erzwingen | force http to https

Andere Lösungen
Post Reply
aceaccis
Posts: 5
Joined: Mon 8. May 2017, 12:27

https erzwingen | force http to https

Post by aceaccis »

English below

Hallo zusammen,

hat zwar nicht unbedingt mit CMSimple zu tun, funktioniert jedoch tadellos und vielleicht wollte der eine oder andere diese Funktion schon immer haben.

Ziel war es den Besucher gezielt von http auf https zu lenken, quasi als erzieherische Maßnahme. Generell publiziere ich die Links zu meiner Webseite immer mit https jedoch neigt der User dazu generell den link ohne dem "s" einzugeben.

Hier wird Serverseitig durch den Apache mit Hilfe der .htaccess der User einfach auf die https weitergeleitet.

Dies funktioniert jedoch nur wenn auch ein SSL Zertifikat vorliegt anderweitig kommt ein Zertifikatsfehler auch auf Sub - Seiten ohne Wildcard-Zertifikate wird ein Fehler erscheinen.

Im CMSimple Root einfach in die .htaccess folgenden Code eintragen und yourdomain.tld durch eure Domain ersetzen:

Code: Select all

AddDefaultCharset UTF-8

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://yourdomain.tld/$1 [R,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]
Bitte denkt daran das nach einem Core Update eventuell dieser Eintrag im .htaccess File ersetzt wird .

Hoffe es ist dem einen oder anderen eine Hilfestellung.

Danke und Gruß
Chris

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Hello ,

the goal was to force the visitor from http to https . In generally, I publish the links to my website always with https, however, the user generally tends to enter the link without the "s".

Apache supoports the redirection by .htacces file in the CMSimple root .

This will only work if an SSL certificate is present, otherwise a certificate error will appear also on sub-pages without wildcard cert.

In the CMSimple root simply enter the following code into the .htaccess and replace yourdomain.tld with your domain:

Code: Select all

AddDefaultCharset UTF-8

RewriteEngine On
RewriteBase /

RewriteCond% {HTTPS}! ^ On $
RewriteRule (. *) https: //yourdomain.tld/$1 [R, L]

RewriteCond% {REQUEST_FILENAME} -s [OR]
RewriteCond% {REQUEST_FILENAME} -l [OR]
RewriteCond% {REQUEST_FILENAME} -d
RewriteRule ^. * $ - [NC, L]

RewriteRule ^. * $ Index.php [NC, L] 
Please remember that after a core update possibly this entry in the .htaccess file will be replaced.

Hope this will help someone.

Thanks and regards
Chris
Bas
Posts: 2
Joined: Wed 10. Jan 2018, 09:46
Contact:

Re: https erzwingen | force http to https

Post by Bas »

Tip:

This solution was not working in my case http://www.gastouder-hasselt.nl

After installing an SSL-certificate by my provider and changing the .htacces-file like discribed, I've got an errormessage:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator and inform them of the time the error
occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

Finally I found another solution and now it's working fine.

I added in the headsection of the template:

<script type="text/javascript">
if(window.location.protocol != 'https:') {
location.href = location.href.replace("http://", "https://");
}
</script>

Also the link version- and update info is again working as earlyer times
:P
Maybe this will help somebody.

Best regards

Bas
Bas
Posts: 2
Joined: Wed 10. Jan 2018, 09:46
Contact:

Re: https erzwingen | force http to https

Post by Bas »

I've found a better and direct solution. This works for me.
I changed the .HTACCESS file in the root of the website in:

AddDefaultCharset UTF-8
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.gastouder-hasselt.nl/$1 [R,L]

I removed the mentioned addition in the template. It looks the https:/-pages are now loading faster.
Gert
Posts: 2065
Joined: Sun 18. Nov 2012, 14:18

Re: https erzwingen | force http to https

Post by Gert »

Hello,

in the most cases you can do it by the providers backend, that's the best way. If a provider offers https:, he should offer this too,

Gert
Gert Ebersbach | CMSimple | Templates - Plugins - Services
Post Reply