I edited the question based on new information.

I know I am a big novice for server configuration stuff.

What I noticed is that mod_dir adds backslash properly in all non-subdomain paths.

For example: https://example.co/test => https://example.co/test/

But when I have a subdomain: https://sub.example.co/test => http://sub.example:443/test/

enter image description here

Here is my default-ssl

 ExpiresActive On
 ExpiresDefault "access plus 1 month"
 Protocols h2 h2c http/1.1
 Alias "/library/" "/var/www/html/example/library/"
 <Directory /var/www/html/>
  Options FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
 <FilesMatch "\.(cgi|shtml|phtml|php)$">
  SSLOptions +StdEnvVars
 <Directory /usr/lib/cgi-bin>
  SSLOptions +StdEnvVars
 <VirtualHost _default_:443>
  ServerName example.co
  DocumentRoot /var/www/html/example
  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/example.co/cert.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/example.co/privkey.pem
  SSLCertificateChainFile /etc/letsencrypt/live/example.co/chain.pem
 <VirtualHost *:443>
  ServerAlias sub.*
  DocumentRoot /var/www/html/example/sub

Here is my 000-default

<VirtualHost *:80>
 RewriteEngine On
 RewriteCond %{HTTPS} off
 RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

Why do my subdomains throw errors and change into HTTP when mod_dir adds directory slashes?

  • SetHandler some-handler - You didn't literally use that "example" as-is did you? DirectorySlash On is the default - so unless you have explicitly disabled this elsewhere in your server config then that is not the issue. You've not included your vHost config for port 80? You have a bunch of directives in a server context followed by a minimal vHost for 443? mod_rewrite directives in a server context are not inherited by the vHost by default anyway. Wild guess is that your HTTP (port 80) ServerName is set (or resolving) incorrectly - perhaps as a result of misconfigured vhosts?
    – MrWhite
    Mar 3, 2019 at 13:42
  • Those ErrorDocument directives are certainly "look wrong" - why would you "redirect" to the document root (these are also missing a trailing slash)? These would only "mask" an underlying error (without looking at your server's error log).
    – MrWhite
    Mar 3, 2019 at 13:44
  • @MrWhite I apologize for my novice-ness in Apache server configurations. I edited the question. I found out that this issue only exists with my virtual hosts (subdomains). Mar 4, 2019 at 21:49


You must log in to answer this question.

Browse other questions tagged .