0

I obtained some proper SSL certificates for our website. I was able to get them installed and tests of the HTTPS side worked great. The only thing left was to redirect all HTTP traffic to HTTPS, and then things went to crap.

I added the following line to my <VirtualHost *:80> area:

Redirect permanent / https://www.website.com/

This caused some interesting behavior in two ways. The first is that all absolute links within the website to a different directory within the website failed. For example a link to http://www.website.com/directory would end up at https://www.website.comdirectory with the obligatory "This site can’t be reached" error. Directly entering in the URL http://www.website.com/directory would give the same behavior.

Would it be better to replace the Redirect statement with this?

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]

Or is something else needed?

  • 2
    Your redirect and rewriterule do exactly the same thing. What you describe is almost always caused by mismatching trailing slashes in redirects or rewriterules. Can you check your http to https redirect and make sure it's as you posted (i.e. check the target URL has the trailing slash)? Otherwise it seems likely there is another redirect/rewriterule you don't know about. – Unbeliever Aug 30 '16 at 17:41
  • There are 4 other Redirect statements in some of the other conf files. They all look similar to this: Redirect permanent /ftp/EMF /emf. None of them include the directory that I have been testing with. – Chris Woelkers Aug 31 '16 at 13:57
0

Try this in .htaccess:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.my-site.com/$1 [R,L]
  • I'm trying to avoid using .htaccess. Will this work in my .conf file? I tried it but the configtest failed saying RewriteCond: bad flag delimiters. – Chris Woelkers Aug 31 '16 at 11:44
  • Maybe try it without the [R, L] ? – user1780242 Aug 31 '16 at 12:26
  • With or without the [R, L], or just removing the space within, the problem was the same. – Chris Woelkers Aug 31 '16 at 13:58
  • Yeah -- the space should have been removed. I have fixed my comment to reflect the correct syntax. When you run the line in www.htaccesscheck.com the syntax checks out okay without the space, but with the space it does throw the warning you mentioned. You might check your string at this URL to make sure you don't have a typo you're missing or something. – user1780242 Aug 31 '16 at 17:31
  • I found it -- the underscore was missing from SERVER_PORT -- try it as written above now. – user1780242 Aug 31 '16 at 18:36
0

So we figured this out.

Because there are multiple config files, each one for a different mounted directory, every one of those config files needed a redirect rule or rewrite rule set.

Now that said rules are in place the website works as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.