1

I'm trying to redirect phpmyadmin to SSL on the default installation of an Ubuntu 12.04. I enabled mod_rewrite and I turned the engine on with:

RewriteEngine On

then, in /etc/phpmyadmin/apache.conf, I added the two lines to redirect, so it looks like this:

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php

    RewriteCond %{HTTPS} off
    RewriteRule ^/phpmyadmin https://%{HTTP_HOST}%{REQUEST_URI}

    <IfModule mod_php5.c>
            AddType application/x-httpd-php .php

            php_flag magic_quotes_gpc Off
            php_flag track_vars On
            php_flag register_globals Off
            php_admin_flag allow_url_fopen Off
            php_value include_path .
            php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
            php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/
    </IfModule>
</Directory>

It is not redirecting. Any ideas what's going on?

2 Answers 2

1

Try this modified config based on your original. Note that I have explicitly added RewriteEngine On, the RewriteCond checks if HTTPS is not on (as opposed to off) and the RewriteRule is slightly tweaked to be more flexible & explicit. Also added logic to explicitly force calls that are not to phpmyadmin to be plain HTTP:

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/(phpmyadmin) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

    RewriteCond %{HTTPS} =on
    RewriteRule !^/(phpmyadmin) http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

    <IfModule mod_php5.c>
            AddType application/x-httpd-php .php

            php_flag magic_quotes_gpc Off
            php_flag track_vars On
            php_flag register_globals Off
            php_admin_flag allow_url_fopen Off
            php_value include_path .
            php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
            php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/
    </IfModule>
</Directory>
1

JakeGould's answer doesn't work for me, possibly as I need to also redirect pages inside the /phpmyadmin directory. Try this:

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

This catches all URIs starting with /phpmyadmin and 301 redirects to HTTPS.

I've tested this with Apache/2.4.25 (Debian) and also MadeWithLove's Htacess Tester.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .