Score:0

Redirect Error website on VPS Ubuntu "www version" redirecting to "apache default page"

me flag

Hi I am a web designer and have recently starting maintaining a VPS server
I am using a Lamp VPS server running ubuntu 18 with multiple PHP websites
have edited virtual host and htaccess multiple times.

Problem :

1.in all websites: all "www version of websites" redirecting to apache homepage
2.non-https version not redirecting to https version

Should I reissue ssl cert for www version seperately ?

Code for Virtual Hosts

<VirtualHost *:80>
    ServerName www.temp.com
    ServerAlias temp.com
    Redirect "/" "https://www.temp.com"
    DocumentRoot /var/www/temp.com/

    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,END]

    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,END]
   </VirtualHost>

Code for .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>

I am using Certbot for SSL certificates using


sudo certbot --apache

HBruijn avatar
in flag
Have youyr plain http and https virtualhosts been activated https://ubuntu.com/tutorials/install-and-configure-apache#5-activating-virtualhost-file
Score:0
in flag
<VirtualHost *:80>

ˆˆˆ A VirtualHost on port 80 should always be the plain, clear text, http host. You can never have both plain http AND https on the same port.
That means that the configuration lines below can NEVER apply and should be omitted:

    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,END]

This Redirect directive:

   Redirect "/" "https://www.temp.com"

is the simple and recommended version of the mod-rewrite code below that is functionally equivalent:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,END]

they both redirect from plain http to https. You don't need both. I recommend deleting the mod_rewrite code.

You certainly don't need to repeat that redirect to https functionality a third time in your .htaccess file.


There should be a code block for a HTTPS VirtualHost that looks something like:

<VirtualHost *:443>
    ServerName www.temp.com
    ServerAlias temp.com
    DocumentRoot /var/www/temp.com/

    SSLEngine on
    SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1

    SSLCertificateFile /etc/letsencrypt/live/.../cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/..../privkey.pem
    SSLCACertificateFile /etc/letsencrypt/live/.../chain.pem

</VirtualHost>

SACHIN HD avatar
me flag
Where should i add the <VirtualHost *:443> block in sites-available/website.conf
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.