How to Automatically Redirect Http to Https on Apache Servers

How to automatically redirect HTTP to HTTPS on Apache servers?

I have actually followed this example and it worked for me :)

NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.example.com
Redirect permanent / https://mysite.example.com/
</VirtualHost>

<VirtualHost _default_:443>
ServerName mysite.example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>

Then do:

/etc/init.d/httpd restart

How to Redirect HTTP to HTTPS on Apache?

Make sure you can access your website both through HTTP and HTTPS. Also make sure mod_rewrite is enabled, then you can add these lines to your .htaccess file.

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

Redirect HTTP to HTTPS on default virtual host without ServerName

Try adding this in your vhost config:

RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

How to automatically redirect users from http:// to https://?

Starting from VisualSVN Server 3.6, you can enable HTTP to HTTPS redirection via server settings. There is an option on the Network tab: Automatically redirect HTTP to HTTPS (listen on port 80). Learn more at https://www.visualsvn.com/support/topic/00144/.

VisualSVN Server Manager Network Tab HTTP to HTTPS

apache redirecting a redirect from http to https

Probably your branch contains /, so your url is STUFOP%2Fdeploy_toolchain. Apache encode such url and the final is STUFOP%252Fdeploy_toolchain.

try this configuration for non secure virtualhost:

<VirtualHost *:80>
ServerName jenkins.example.net
# this prevent encoding
AllowEncodedSlashes on
Redirect permanent / https://jenkins.example.net/
</VirtualHost>

This configuration should avoid encoding and, according to Redirect Request to SSL Apache wiki page, all request are redirected to secure virtualhost.

In secure virtualhost, try this configuration:

<VirtualHost *:443>

ServerName jenkins.example.net

AllowEncodedSlashes on

proxyRequests Off
ProxyPreserveHost On
ProxyPassMatch "^/(.*)/redirect$" "http://127.0.0.1:8080/$1"
ProxyPass / http://127.0.0.1:8080/ nocanon
ProxyPassReverse / http://127.0.0.1:8080/

ErrorLog /etc/ssl/error_log

SSLEngine on
SSLCertificateFile /etc/ssl/certs/fopjenkins.pem
SSLCertificateKeyFile /etc/ssl/certs/fopjenkins.key
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"

</VirtualHost>

This configuration should avoid encoding and use ProxyPassMatch to manipulate url.

Here is some useful link that I've used: %2F slash encoding issues, encode URL wihthin URL - apache mod-proxy (ProxyPass), %2F slash encoding issues #399, htaccess howto rewrite an encoded slash in url

How to redirect all HTTP requests to HTTPS

Update: Although this answer has been accepted a few years ago, note that its approach is now recommended against by the Apache documentation. Use a Redirect instead. See this answer.


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

How to force redirect http to https on a apache reverse proxy server?

Recommended and also safer way is using VirtualHost:

<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>

or

<VirtualHost *:80>
ServerName www.example.com
Redirect permanent /login https://www.example.com/login
</VirtualHost>

The other way is using mod_rewrite:

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

As I said, Apache recommends using VirtualHost config.

Examples taken from:

https://wiki.apache.org/httpd/RedirectSSL

https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

How do you redirect HTTPS to HTTP?

This has not been tested but I think this should work using mod_rewrite

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

How to automatically redirect HTTP to HTTPS on Apache servers?

I have actually followed this example and it worked for me :)

NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.example.com
Redirect permanent / https://mysite.example.com/
</VirtualHost>

<VirtualHost _default_:443>
ServerName mysite.example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>

Then do:

/etc/init.d/httpd restart



Related Topics



Leave a reply



Submit