The Apache Haus Forum

Forum Topics => Apache 2.4 => Topic started by: casi91 on December 21, 2012, 11:54:16 AM

Title: http always to https
Post by: casi91 on December 21, 2012, 11:54:16 AM
Hi Community,
i want to redirect every http request to https.

I found the "mod_rewrite" for this problem, but it doesn't work.

I tried it in a many ways,
hier some of them:
Code: [Select]
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^/(.*)$ https://www.site.de [R=301,L]

Code: [Select]
RewriteEngine On
RewriteCond %{SERVER_PORT} ^!443
RewriteRule ^/(.*)$ https://%{SERVER_NAME}%{REQUEST_URI}  [R=301,L]

Code: [Select]
RewriteEngine On
RewriteCond %{SERVER_PORT} ^!443
RewriteRule (.*)$ https://%{SERVER_NAME}%{REQUEST_URI}  [R=301,L]

Code: [Select]
RewriteEngine On
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

can somebody help me?
Title: Re: http always to https
Post by: Jan-E on December 21, 2012, 12:41:48 PM
Within the <VirtualHost for port 80>

   <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond      %{HTTP_HOST}   ^(example.com|www.example.com)$
      RewriteRule ^/(.*)   https://www.example.com/$1 [R,L]
   </IfModule>
</VirtualHost>
Title: Re: http always to https
Post by: casi91 on December 21, 2012, 01:29:58 PM
Thanks for your answer

I did it with "redirect", but how you said, within the virtual host.
Code: [Select]
<VirtualHost for port 80>
....
Redirect permanent / https://www.site.de
</VirtualHost>