NotionCommotion Posted August 17, 2019 Share Posted August 17, 2019 Hoping to get another set of eyes. Why isn't this redirecting? I put http://test.example.com in the browser, and it sometimes redirects and sometimes doesn't. I've removed any .htaccess files just to be sure. Thanks <VirtualHost *:80> ServerName test.example.com DocumentRoot /var/www/concrete5/public <Directory "/var/www/concrete5/public"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all RewriteEngine On </Directory> RewriteCond %{SERVER_NAME} =test.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerName test.example.com DocumentRoot /var/www/concrete5/public <Directory "/var/www/concrete5/public"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all RewriteEngine On </Directory> Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/test.example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/test.example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/test.example.com/chain.pem </VirtualHost> </IfModule> Quote Link to comment Share on other sites More sharing options...
kicken Posted August 17, 2019 Share Posted August 17, 2019 Your RewriteCond is unnecessary. %{SERVER_NAME} resolves to whatever the ServerName directive is, so that condition is always true. %{HTTP_HOST} would be the name the request uses. Unless this is your default vhost that should also always be equal to test.example.com though as you have no ServerAliases.. If you just want every non-https request to go to https, there is a simpler way: <VirtualHost *:80> ServerName test.example.com Redirect permanent / https://test.example.com </VirtualHost> This is what I use for pretty much all my sites. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted August 18, 2019 Author Share Posted August 18, 2019 (edited) Thank you kicken, While I think you are mostly correct, not sure if you are completely correct, but you definitely solved me problem! For whatever reason, I just do not enjoy configuring web servers which makes me not very good at it which causes me mysterious issues such as this. Instead, I too often copy and paste and assume things are correct. For https, I use letsencrypt, and just execute sudo certbot --apache which automatically updates the http config file and creates the https config file. After reading your post, I first confirmed that other sites which I do such for are correctly redirecting, and then I compared the conf files to this problem site. For unknown reasons, this just happened to leave out the RewriteEngine on line, and after adding it, it works as expected. Agree your solution is simpler and I believe it is the same as I previously was using before using letsencrypt. Thanks again! <VirtualHost *:80> ... <Directory "/var/www/concrete5/public"> ... </Directory> RewriteEngine on RewriteCond %{SERVER_NAME} =test.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost> Edited August 18, 2019 by NotionCommotion Quote Link to comment Share on other sites More sharing options...
kicken Posted August 18, 2019 Share Posted August 18, 2019 You had RewriteEngine On, just inside your directory section instead of the VirtualHost. Didn't think it would have mattered so didn't mention that. 7 hours ago, NotionCommotion said: Agree your solution is simpler and I believe it is the same as I previously was using before using letsencrypt. Not sure if your saying using Let's Encrypt made you change or not, but I use Let's Encrypt and cetbot just fine with the simple redirect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.