If it were me; I would set up to give the http its own directory and redirect anything that would be a 404 to the https using the .htaccess of http location. This keeps things easy to understand for any future revisits to how the site is working, and uses coding that is well established and followed by anyone else who may need to work on the site.
A a2enmod rewrite (apache2) may be required if you are self hosting or VPS hosting to enable rewrite mod; but it appears to be already enable? in your case.
The .conf you are using
<VirtualHost *:80>
ServerName somewhere.com
ServerAdmin [email protected]
DocumentRoot /var/www/port80-somewhere.com
ErrorLog /etc/httpd/logs/error_log_somewhere
CustomLog /etc/httpd/logs/access_log_somewhere combined
</VirtualHost>
# allow .htaccess over ride may already be allowed.
<Directory /var/www/port80-somewhere.com/>
Options -Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
CentOS 7 may want to AllowOverride here /etc/httpd/conf/httpd.conf But
I think it is already allowed.
<Directory /var/www/port80-somewhere.com/>
Options -Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
/var/www/port80-somewhere.com/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ "https://example.com/$1" [R=301,L]
Thus; if version.txt exists in /var/www/port80-somewhere.com/ it will be presented from port 80. Anything that does not exist in /var/www/port80-somewhere.com/ is 301ed to the secure site. So you can pick and choose at will what will be available on http without needing to reconfigure.
Note: I would also put the favicon.ico in /var/www/port80/favicon.ico because the browser will ask for it.
Update
The .htaccess is a derivative of Apache documentation, which is in common usage by Wordpress sites.
# Apache configuration file
# http://httpd.apache.org/docs/2.2/mod/quickreference.html
# Turning on the rewrite engine is necessary for the following rules and
# features. "+FollowSymLinks" must be enabled for this to work symbolically.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Except as you noted does not redirect the root of the domain itself. Sorry I missed that.
- First condition... the file "-f" requested does not "!" exist.
- Second condition ... the request is not "!" a directory "-d"
- Third condition ... we don't want the root index.php or index.html
either. If the request URI is HTTP://example.com/ the requested URI is "/" or ^/$ as the condition.
The one you are using per comments is good. My thought of using the %{REQUEST_URI} is that if revisited in the future the only thing that may need to be changed is the site within "". So less things to go wrong.
If conditions are true 301 to new location.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ "https://example.com/$1" [R=301,L]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ "https://example.com/$1" [R=301,L]
We need to use the rewrite engine. Depending on the build if one is using the installed version of apache from the linux os. It may not be turned on? Apache came to the rescue with a2enmod ... which allows it to be turned on in a way that will not break on a future release, (thank you Apache).
The virtual host looks fairly off the shelf so it will not break in future releases. But we need to allow .htaccess so we can configure directories to rewrite etc using .htaccess so that we don't need to restart the server. The derivative of /etc/apache2/sites-available/000-default.conf
use AllowOverride all.
<Directory /var/www/port80-somewhere.com/>
Options -Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
Specifically in the directory where HTTP exists. We want .htaccess enabled. "AllowOverrided all" does this; and "Require all granted" is the newer syntax of "Allow from all" which relates to blocking IP addresses from access to the host, don't want to block anyone, "all granted"; The -Indexes is turning off listing of the files in a directory, there is not one but we don't want to need to change this if usage changes.
All these might be turned on by some builds but if we need to move the site, nice if we can do that without issues.