2016-02-02 7 views
5

Ich habe keine Ahnung, warum dies fehlschlägt. Ich möchte nur alle Domain zu www.maindomain.com und http zu https umleiten, was fehlt mir?Apache2 Redirect zu einer anderen Domäne mit ssl

# redirect http to https  
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

# redirect without www to www 
RewriteCond %{http_host} ^maindomain.com [nc] 
RewriteRule ^(.*)$ https://www.maindomain.com [r=301,nc] 

# redirect another domain to www.maindomain.com  
RewriteCond %{HTTPS} off # this i was missing 
RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain.com [NC] 
RewriteRule ^(.*)$ https://www.maindomain.com [R=301,L] 
  1. http://maindomain.com zu https:/www.maindomain.com/ arbeitet
  2. http://anotherdomain.com-https:/www.maindomain.com/ arbeitet
  3. https://anotherdomain.com-https:/www.maindomain.com/
für eine andere Domain
+0

seltsam, der Kommentar mit der RewriteCond% {HTTPS} aus, Hinweis war richtig, es funktioniert jetzt, aber die Antwort wurde gelöscht, gerade als ich es akzeptieren wollte, fehlte mir ein 2. RewriteCond in der 3. Weiterleitung –

Antwort

1

Die Http Https Umleitung nicht gescheitert, weil die Regel ist die folgende Zeile fehlt :

RewriteCond %{HTTPS} off 

Versuchen:

# redirect another domain to www.maindomain.com  

RewriteCond %{HTTPS} off 

RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain.com [NC] 
RewriteRule ^(.*)$ https://www.maindomain.com [R=301,L] 
0

Sie können dies versuchen:

RewriteEngine On 
RewriteCond %{HTTPS} !on 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

Kopieren Sie einfach und der obige Code in .htaccess-Datei einfügen dann die gesamte Website auf „https“ umgeleitet wird, wenn die Browser wird im "http" -Modus geöffnet. Der Browser wird nur per URL-Umschreiben in .htaccess umgeleitet.

Verwandte Themen