0

I have enabled https and can navigate application using HTTP and HTTPS without rewrite. Apache 2.2.24. But I see a strange behavior:

Receiving 400 bad request if passing http://hostname.com/XXX but works fine with url/xxx/ Don’t know how / can help to redirect to https.

Also, enabled the rewrite with following in httpd.conf but don’t see a difference. Also, HTTP redirection is not working.

Rewrite Engine

RewriteEngine On

now the rewriting rules

RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://hostname.com/XXX [R,L]`
grebneke
  • 4,414
  • 17
  • 24
  • Try replacing your condition with `RewriteCond %{HTTPS} =off`. – Palec Jan 31 '14 at 10:14
  • A related one: [Correctly switching between HTTP and HTTPS using .htaccess](http://stackoverflow.com/q/1108706/2157640) – Palec Jan 31 '14 at 10:17

1 Answers1

0

The simpliest way to do that is to make 2 virtualhosts, one listening on IP:80 (HTTP) redirecting to HTTPS and the other listening on IP:443 (HTTPS).

<VirtualHost private_ip_of_your_server:80>
    ServerName www.mywebsite.com

    ErrorLog /var/log/apache/http_www_mywebsite_com_error.log
    CustomLog /var/log/apache/http_www_mywebsite_com_access.log combined

    RedirectPermanent / https://www.mywebsite.com/
</VirtualHost>

<VirtualHost private_ip_of_your_server:443>
    ServerName www.mywebsite.com

    ErrorLog /var/log/apache/https_www_mywebsite_com_error.log
    CustomLog /var/log/apache/https_www_mywebsite_com_access.log combined
</VirtualHost>

Don't forget to add the two associated NameVirtualHost directives: - NameVirtualHost private_ip_of_your_server:80 - NameVirtualHost private_ip_of_your_server:443

Regards

gr0bz
  • 189
  • 1
  • 2
  • 11