Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following conf files:




    RedirectPermanent /

#   RewriteEngine On
#   RewriteCond %{SERVER_PORT} !^443$
#   RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [L,R]

#   SSLRequireSSL
#   Redirect permanent /secure

#   Redirect /

As you can see from the commented out lines, I have tried several approaches.



    DocumentRoot "/opt/www/example-docroot"
    DirectoryIndex index.html
    SSLEngine on

    SSLCertificateFile /etc/httpd/conf.d/ssl/
    SSLCertificateKeyFile /etc/httpd/conf.d/ssl/
    SSLCACertificateFile /etc/httpd/conf.d/ssl/

    <Files ~ "\.(cgi|shtml|phtml|php3?)$">
        SSLOptions +StdEnvVars
    <Directory "/etc/httpd/cgi-bin">
        SSLOptions +StdEnvVars

Some thing removed for simplicity, names changed to protect the innocent.

I update these files on the server /etc/httpd/vhosts

then run

apachectl restart

Which does give me these warnings:

[warn] NameVirtualHost has no VirtualHosts
[warn] NameVirtualHost has no VirtualHosts

We have numerous vhosts running from this server. The above configs seem to be aligned, so I don't think these warnings are applying here. Maybe wrong.

Updating the default 80 (http) page in my browser, always shows the default http page.

Any suggestions, on how to get the redirect to work?

share|improve this question
Just to confirm, I hope that's not the actual IP address in use. – Brian Showalter Oct 2 '12 at 12:53
Yes, that's just an example IP. – Jahmic Oct 3 '12 at 3:21
This issue has become a low priority, at the moment, or perhaps even resolved already. I'll try to look into it a bit more and whose ever answer is the closet will get the mark. – Jahmic Oct 3 '12 at 3:24
up vote 2 down vote accepted

Many examples work on specific configurations. This one always works, no matter which configuration your Apache server uses:

RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(/(.*))?$ https://%{HTTP_HOST}/$1 [R=301,L]
share|improve this answer

I had faced exactly the same issue few days back. I tried the following in my VirtualHost config (applicable for http port 80) in apache httpd.conf file that worked.

<Virtualhost *:80>

RedirectMatch permanent ^(.*)$$1

This works like charm and you don't need any config anywhere else or any extra module.

share|improve this answer
Thanks. But this isn't working for me. I'm suspecting it's not so much about the config commands, but something else... – Jahmic Aug 24 '12 at 3:25
+1 for not using mod_rewrite. – pjmorse Oct 4 '12 at 0:44

Better use .htaccess for this (if possible), no need to mess with the apache config files. Add these lines to the beginning of your .htaccess.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
share|improve this answer
It's definitely not better to use .htaccess because Apache ends up doing unnecessary work (like mapping URLs to filesystem paths) before performing the redirect as hinted at in point 1 here. (Also, the docs recommend against using mod_rewrite for simple redirection) – nickgrim Aug 23 '12 at 8:50
Nice point and useful information. My answer may still apply to those that don't have access to the apache config files however. – drcelus Aug 23 '12 at 11:17
Odd. Even this doesn't work. Something else is going on... In any case, I'd rather do with a conf command than this, but this is a good solution as a fall back plan. – Jahmic Aug 24 '12 at 3:28

I think last time this happened to me it may have been something weird like NameVirtualHost *:80/NameVirtualHost *:443 and/or Listen 80/Listen 443 were somewhere other than ports.conf for apache2.

Here is what I have in VirtualHost to redirect to https for all pages except for press (had a video that couldn't be served https so had to redirect back to http otherwise people would get ugly warnings about the page being unsafe):

<VirtualHost *:80>
    RewriteEngine On

    RewriteCond %{REQUEST_URI} !^/press/.*
    RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]
share|improve this answer
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1
share|improve this answer
This is lacking some explanation. – kasperd Aug 11 '15 at 6:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.