title: Express.js app adding an extra slash to the request url
body: <p>I am running an express.js web app on an Apache2 server. Right now, the app is pretty basic, and all I'm trying to do is print the request URL to the console. For example, when I access <a href="https://subdomain.example.com/node/something" rel="nofollow noreferrer">https://subdomain.example.com/node/something</a> in my browser, I expect it to print <code>/something</code> to the console. Instead, it prints <code>//something</code> (notice the extra slash at the beginning). This means that any route handlers I write would be thrown off. At the moment, I really don't know what could be causing this.<br />
  A point that might be relevant is that I'm using Apache's mod_rewrite to remove the www. at the beginning of the URL, and the file extensions (.php etc.) from the end. I've tried commenting these out to see whether this changes it, but it didn't.</p>
  <p>My app:</p>
  <pre class="lang-js prettyprint-override"><code>const express = require('express');
  
  const PORT = 8080;
  const app = express();
  
  app.use((req, res) =&gt; {
      console.log(req.url);
      res.status(200).send()
  });
  
  app.listen(PORT, () =&gt; {
      console.log(`App listening on port ${PORT}`)
  })
  </code></pre>
  <p>My Apache vhost config:</p>
  <pre><code>&lt;IfModule mod_ssl.c&gt;
  &lt;VirtualHost *:443&gt;
  
          Alias /fonts /usr/share/fonts/www
  
          &lt;Directory &quot;/fonts&quot;&gt;
                  Require all granted
          &lt;/Directory&gt;
  
          &lt;Directory &quot;/errors&quot;&gt;
                  Require all denied
          &lt;/Directory&gt;
  
          &lt;Directory &quot;/&quot;&gt;
                  DirectoryIndex login.php
          &lt;/Directory&gt;
  
          ServerName admin.example.com
          ServerAlias www.admin.example.com
  
          DocumentRoot /var/www/admin.example.com
          ErrorDocument 403 /errors/nope.html
          ErrorDocument 404 /errors/nope.html
  
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
          LogLevel alert rewrite:trace6
  
          ProxyRequests Off
          ProxyPreserveHost On
          ProxyVia Full
  
          &lt;Proxy *&gt;
                  Require all granted
          &lt;/Proxy&gt;
  
          &lt;Location /node&gt;
                  ProxyPass http://127.0.0.1:8080/
                  ProxyPassReverse http://127.0.0.1:8080/
          &lt;/Location&gt;
  
          RewriteEngine On
  
          RewriteCond %{HTTP_HOST} ^www\.admin\.example\.com$
          RewriteRule ^/(.*)$ http://admin.example.com/$1 [R=301,L]
  
          RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
          RewriteRule ^(.+)/$ $1 [R=301]
  
          RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}\.php -f
          RewriteRule (.*) $1.php
  
          RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
          RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -f
          RewriteCond %{REQUEST_URI} ^(.+)\.php$
          RewriteRule (.*)\.php$ $1 [R=301,L]
  
          Include /etc/letsencrypt/options-ssl-apache.conf
          SSLCertificateFile /etc/letsencrypt/live/admin.example.com/fullchain.pem
          SSLCertificateKeyFile /etc/letsencrypt/live/admin.example.com/privkey.pem
  &lt;/VirtualHost&gt;
  &lt;/IfModule&gt;
  </code></pre>
  <p>Any help would be much appreciated.</p>
  <p><strong>Update:</strong> I moved the .js file out of the /node folder and into the root directory of the Apache site, and that fixed the issue somehow. However, I still want to be able to move it into a folder without having problems.</p>