Score:0

example.com to https://www.example.com | Apache

in flag

So I want to redirect example.com to https://www.example.com. I already have ssl with certbot but I want to change my redirect config in /etc/apache2/sites-available/example.conf.

Certbot already gives you a redirect from example.com to https://example.com.

this is my current apache config

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
us flag
Does this answer your question? [Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About mod\_rewrite Rules but Were Afraid to Ask](https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever)
Thamognya Kodi avatar
in flag
@TeroKilkanen Yup this answers it. Thank you.
Score:2
cn flag
Bob

The recommended configuration for simple redirects is to avoid rewrite rules and simply set up a Redirect directive:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent "/" " https://www.example.com/" 
</VirtualHost>
Thamognya Kodi avatar
in flag
This sadly does not answer my question as rewrite engine is required and made use of by certbot.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.