AMR Plugin .htaccess HTTPS

Gesperrt
csandro
Beiträge: 44
Registriert: Mo 30. Jan 2012, 02:25
Kontaktdaten:

AMR Plugin .htaccess HTTPS

Beitrag von csandro » Do 25. Jul 2013, 07:38

Hallo,

ich habe ein kleines Problem und hoffe auf eure Unterstützung.

Ich möchte für meine Seite nun ein SSL Zertifikat nutzen. Alles was das Zertifikat
betrifft inkl. einbindung ist Erledigt.

Info: ich nutze das AMR Plugin

Nun möchte ich aber erreichen, dass man meine Seite mit und ohne https aufrufen
kann. Derzeit werden über die htaccess alle Aufrufe nach folgendem Schema
mit mod_rewrite umgeleitet:

Code: Alles auswählen

RewriteCond %{HTTP_HOST} ^meinedomain\.de$ [NC]
RewriteRule ^(.*)$ http://www.meinedomain.de/$1 [R=301,L]
Das scheint mir derzeit die Nutzung von https auszuschließen. Was muss ich tun, wenn
weiterhin immer auf die Variante mit www. umgeleitet werden soll, aber die freie
wahl zwischen http und https bestehen soll?

Ich nutze derzeit folgende .htaccess:

Code: Alles auswählen

###############################################################################
# Contenido AMR plugin simple rewrite rules set
#
# Contains few easy to handle rewrite rules
#
###############################################################################


# Enable following lines to run PHP5 on 1und1.de (1and1.com)
# ----------------------------------------------------------
#AddType x-mapp-php5 .php
#AddHandler x-mapp-php5 .php

<IfModule mod_rewrite.c>

# Enable rewrite engine
# ---------------------
RewriteEngine on
# This will enable the Rewrite capabilities

RewriteCond %{HTTP_HOST} ^meinedomain\.de$ [NC]
RewriteRule ^(.*)$ http://www.meinedomain.de/$1 [R=301,L]

RewriteCond %{HTTP_HOST}                 ^anderedomain.de$ [NC]
RewriteRule ^(.*)           http://www.meinedomain.de/$1 [L,R=301]
RewriteCond %{HTTP_HOST}             ^www.anderedomain.de$ [NC]
RewriteRule ^(.*)           http://www.meinedomain.de/$1 [L,R=301]


# Specify a base URL-path for the rules
# -------------------------------------
RewriteBase /cms


# Catch some common exploits in query string to get rid of them
# NOTE: Conditions to prevent protocolls (ftp, http[s]) in query string could be a
#       disadvantage in some cases
# --------------------------------------------------------------------------------
RewriteCond %{QUERY_STRING} contenido_path=.*$  [NC,OR]
RewriteCond %{QUERY_STRING} cfg\[path\]=.*$  [NC,OR]
RewriteCond %{QUERY_STRING} _PHPLIB\[libdir\]=.*$  [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} ftp://.*$  [NC,OR] 
RewriteCond %{QUERY_STRING} http[s]*://.*$ [NC] 
RewriteRule ^.* - [F,L]  # all matching conditions from above will end in nirvana


# Rewrite request to root to front_content.php
# --------------------------------------------
RewriteRule ^$ front_content.php [QSA,L]


# Exclude following request from rewriting
# tests for valid symlinks (-s), not empty files (-l) and folders (-d)
# --------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d      
RewriteRule ^.*$ - [NC,L]


# Pass other requests to front_content.php
# ----------------------------------------
RewriteRule ^.*$ front_content.php [QSA,NC,L]


</IfModule>
Vielen Dank schon mal

csandro

xmurrix
Beiträge: 3147
Registriert: Do 21. Okt 2004, 11:08
Wohnort: Augsburg
Kontaktdaten:

Re: AMR Plugin .htaccess HTTPS

Beitrag von xmurrix » Do 25. Jul 2013, 08:14

Hallo csandro,

hast du mal folgende Regeln probiert:

Code: Alles auswählen

# wenn https aus ist und domain meinedomain.de, dann weiterleitung zu http://www.meinedomain.de
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^meinedomain\.de$ [NC]
RewriteRule ^(.*)$ http://www.meinedomain.de/$1 [R=301,L]

# wenn https an ist und domain meinedomain.de, dann weiterleitung zu https://www.meinedomain.de
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^meinedomain\.de$ [NC]
RewriteRule ^(.*)$ https://www.meinedomain.de/$1 [R=301,L]
Alternativ sollte das auch mit Überprüfung des Serverports gehen:

Code: Alles auswählen

# wenn port nicht 443 ist und domain meinedomain.de, dann weiterleitung zu http://www.meinedomain.de
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} ^meinedomain\.de$ [NC]
RewriteRule ^(.*)$ http://www.meinedomain.de/$1 [R=301,L]

# wenn port 443 ist und domain meinedomain.de, dann weiterleitung zu https://www.meinedomain.de
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^meinedomain\.de$ [NC]
RewriteRule ^(.*)$ https://www.meinedomain.de/$1 [R=301,L]
Habe das allerdings nicht getestet, vermute aber dass das so möglich sein sollte...

Gruß
xmurrix
CONTENIDO Downloads: CONTENIDO 4.10.1
CONTENIDO Links: Dokumentationsportal, FAQ, API-Dokumentation
CONTENIDO @ Github: CONTENIDO 4.10 - Mit einem Entwicklungszweig (develop-branch), das viele Verbesserungen/Optimierungen erhalten hat und auf Stabilität und Kompatibilität mit PHP 8.0 bis 8.2 getrimmt wurde.

Spider IT
Beiträge: 1416
Registriert: Fr 3. Dez 2004, 10:15

Re: AMR Plugin .htaccess HTTPS

Beitrag von Spider IT » Do 25. Jul 2013, 14:20

Das funktioniert aber nur dann, wenn die Generierung des base href nicht durch Contenido, sondern per Modul erfolgt:

Code: Alles auswählen

<?php
$sHtmlPath = $cfgClient[$client]['path']['htmlpath'];
if ($_SERVER['SERVER_PORT'] == 443) {
    echo '<base href="' . str_replace('http://', 'https://', $sHtmlPath) . '" />';
} else {
    echo '<base href="' . str_replace('https://', 'http://', $sHtmlPath) . '" />';
}
?>
Sonst gehen alle Links der Seite (inkl. JS, CSS, Bilder usw.) weiterhin auf die Version, die beim Mandanten als Pfad hinterlegt ist.

Gruß
René

Gesperrt