Apache: prevent SSL redirection of a specific URL

1

My server (Apache 2x) is working properly with SSL certificate but I need to prevent only a single URL from accepting normal (HTTP only) connection.

The current structure looks like this (it's messed up, due to tests already done)

<VirtualHost *:80>
            ServerName domain.com
            ServerAlias www.domain.com

            #Redirect permanent / https://domain.com/

        <IfModule mod_rewrite.c>
                    RewriteEngine on
                    RewriteCond %{HTTPS} on
                    #RewriteCond %{SERVER_NAME} =domain.com
                    RewriteCond %{REQUEST_FILENAME} !-f
                    RewriteCond %{REQUEST_FILENAME} !-d
                    RewriteCond $1 !^/complemento/url [NC]
                    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
        </IfModule>
            Redirect permanent / https://domain.com/
</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost *:443>
            ServerAdmin [email protected]
            ServerName domain.com
            ServerAlias www.domain.com
            DocumentRoot /var/www/html

            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined

            SSLEngine on

            SSLCertificateFile      /home/domain/domain.com.crt
            SSLCertificateKeyFile /etc/apache2/ssl/domain.key
            SSLCertificateChainFile /home/domain-bundle.crt

            <FilesMatch "\.(cgi|shtml|phtml|php)$">
                            SSLOptions +StdEnvVars
            </FilesMatch>
            <Directory /usr/lib/cgi-bin>
                            SSLOptions +StdEnvVars
            </Directory>

            <Directory /var/www/html>
                    Options FollowSymLinks
                    AllowOverride All
            </Directory>
    </VirtualHost>
</IfModule>

This way it does not work. How to proceed?

    
asked by anonymous 08.02.2018 / 16:48

2 answers

-1

I solved the problem as follows:

  • I removed the redirect from the default-ssl.conf (Apache)
  • Because this is a system in CakePHP, I edited the .htaccess inside / app / webroot and inserted the redirect there, getting as below

    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        RewriteCond %{HTTPS} on
        RewriteCond ${REQUEST_URI} ^/reports/producao_logs/add/[a-zA-Z0-9]+?$
        RewriteRule http://{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    

I had to do it this way because previous solutions were redirecting to link app / webroot / address and, with

    
15.02.2018 / 15:44
2

See this example:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ErrorLog /var/log/apache2/error.log

        DocumentRoot /var/www/html

        RewriteEngine On
        RewriteCond %{REQUEST_URI} !^/complemento/url/?$
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

Where:

  • link , will not be redirected to HTTPS
  • link , will not be redirected to HTTPS
  • Any other URL will be redirected to HTTPS

No need to use Redirect permanent / https://domain.com/

    
15.02.2018 / 12:26