Jump to content
sanjom

Let's Encrypt .htaccess Conditions

Recommended Posts

Hey, I've used ProcessWire for a while now but not made an appearance in the forum yet :D I just wanted to share the solution to a small problem I came across with Let's Encrypt (free SSL service).

Let's Encrypt SSL certificates need to be renewed every few months to remain active. My web host does this automatically but needs access to a folder named ".well-known", which ProcessWire blocks by default because it starts with a dot. This results in a 403 error.

To work around this, just add the following line to your .htaccess file, around line 150:

RewriteCond %{REQUEST_URI} !^(/\.well-known)

It should be the first condition in the section titled "Access Restrictions: Keep web users out of dirs that begin with a period".

I also ran into another problem. Let's Encrypt accesses mail.example.com which is redirected to www.mail.example.com because I enabled the redirection in my .htaccess fie. So we need to exclude the mail sub domain from that rule using the following line as the second condition in the www-redirection section (around line 160):

RewriteCond %{HTTP_HOST} !^mail\. [NC]

I know it's quite a specific problem but maybe it'll help someone Googling the issue.

I was curious, is there any way of redirecting to the www-version without having to exclude all your sub domains? The only way I can think of involves explicitly writing out your domain name in the .htaccess file and redirecting whenever the %{HTTP_HOST} starts with that name. But obviously that would lead to a loss of generality.

  • Like 5

Share this post


Link to post
Share on other sites

Hi,

6 hours ago, sanjom said:

It should be the first condition in the section titled "Access Restrictions: Keep web users out of dirs that begin with a period".

As far as I know, since ProcessWire 3.0.29 we have RewriteRule "(^|/)\.(?!well-known)" - [F] there by default. See: https://processwire.com/blog/posts/pw-3.0.29/#summary-of-added-pull-requests

 

 

  • Like 5

Share this post


Link to post
Share on other sites

I'm still having an issue with this. Both with my older PW sites and my newer 3.0+ sites. I can see the rule in the htaccess, but .well-known is still blocked. Any ideas?

Share this post


Link to post
Share on other sites

Have you checked permission of .well-known??

Gideon

Edit: Just found this:

RewriteRule "(^|/)\.(?!well-known)" - [F]

to  .htaccess to section 12.

Share this post


Link to post
Share on other sites

I have not been having this kind of problem since 3.0.29.  My issue is I have the htaccess file  forcing https and that breaks the renewal process.  Currently I rename the htaccess to something like htaccess1, then do the renewal manually then rename the htaccess file back to normal.  Anyone have a tip on how I can still use the automated way with https?   Sorry to hijack this thread.

Share this post


Link to post
Share on other sites

I am using acme.sh with the webroot validation mode and don't have an issue with https for renewal.  However, I put this in my .htaccess in case I ever have to start from scratch.

  RewriteCond %{HTTP:X-Forwarded-Proto} =http
  RewriteCond %{REQUEST_URI} "!(^|/)\.well-known"
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The interesting bit is the 2nd line, which effectively says "to redirect from http to https, the URI cannot match .well-known or anything/.well-known".

In the PW-installed .htaccess this is the #9 block of directives that redirects from http to https, not the #12 block of access control restrictions. The sense of the comparison with ".well-known" here is different than in block #12.  Additionally, the exact format of the 1st line will depend on how your web server frontend/load-balancer is configured.  Alternatives involve %{HTTPS}, %{HTTP:X-Forwarded-SSL}, %{HTTP:Forwarded}, etc, and you should not change whatever is already working for you in the 1st line.

Share this post


Link to post
Share on other sites

I'm currently having this problem on siteground. Running multisite pw the .well-known directory and files are not created, let alone accessible. If I create the directories in the pw/ directory and try accessing them directly I can browse to them, but if I use one of the multisite domains it will not find the directory in pw/ - should it be looking somewhere else? Do I need to alter the base directory for each multisite? They are currently all pointing at the pw/ directory.

Thanks!

Share this post


Link to post
Share on other sites
5 hours ago, gornycreative said:

If I create the directories in the pw/ directory and try accessing them directly I can browse to them, but if I use one of the multisite domains it will not find the directory in pw/ - should it be looking somewhere else? Do I need to alter the base directory for each multisite? They are currently all pointing at the pw/ directory.

There are different possible approaches, but this should work:

  • create a subdirectory in your web root for every domain, named exactly like the domain
  • make sure ownership is correct
  • add a rewrite rule in .htaccess before #12 that prepends the requested host name to the path:
  RewriteCond %{REQUEST_URI} ^/?\.well-known
  RewriteRule "(^|/)(.*)$" $1%{HTTP_HOST}/$2 [L]

  • start letsencrypt with webroot option pointing to /path/to/pw/domain-in-question for every domain
  • enjoy

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Peter Knight
      Can anyone tell me which .htaccess directive might be blocking a site import feature from scanning my public_html folder and listing all files and folders.
      These would be both PW files/folders but also some non PW folders which my PW site references for media.
      Latest .htaccess file on Github
      I can see various options from Section 15 onwards (# 15. Access Restrictions (v301)) but nothing that would block both SSH and FTP scans my VPS site import file uses.
      When I point the same site import tool at a non PW site on the same directory it works.
      I could disable htaccess temporarily but it's a busy and active site.
      Thanks
      P

       
       
    • By daniel_puehringer
      Hi Community,

      Sadly I cannot intall ProcessWire on my webserver (Hosted at https://www.world4you.com/de/startseite.html, a small hosting provider in Austria)
      Here is the Problem: 
      1. I downloaded the current masterbranch as a .zip file (After a few tries I also downloaded the code via the git clone command, that led to the same error), unzipped it and transferred it to my server. Since there is already a wordpress site installed on the root directory, I transferred the processwire files into /relaunch and created a subdomain.
      2. I tried to install the language starter kit. As soon as I navigate to that folder Screenshot1 (see attached file 'processWireBug1') is shown. Everything looks nice, except the red text referring to the 'mod_rewrite' rule. The webserver provides the 'apache mod_rewrite' rule.
      3. As soon as I want to press 'Check again' or 'Continue to next step' an error Page with 500 error (see Screenshot 'processWireBug2') occurs.
      4. You can find my .htaccess file attached to this post..htaccess

      How could I solve this issue?

      Some additional information:
      1) the webserver provides the apache mod_rewrite (I checked that several times) and has php version 7.3. installed.
      2) since there is a wordpress site installed on the root directory, there is also a .htaccess file on the root directory. Could this .htaccess file have an impact on the .htaccess file for my processwire website?

      Thanks for your help and greetings from Austria,
      Daniel


    • By horst
      Hi, on a site I want to disable access to original images and only allow to access thumbnails and watermarked image variations.
      EDIT:
      A good solution for protecting original images can be found a bit down in this thread:
       
      Old content of this initial post:
       
    • By Peter Knight
      Hi all
      My .htaccess file is correctly redirecting all requests to
      https:// www. That's great until I want to work locally.
      I thought I had seen a blog post by Ryan where there was a new config setting to ignore both of these if working from localhost?
      I can't find it now so wondering if I was imagining 😕
       
       
    • By ce90
      Hello everyone,
      hopefully this is the right place to ask and is not a duplicate question.
      I'm pretty new to processwire, so... if this question is kind of funny for some of you, you're welcome 😄 
      I have the following issue and can't find anything understandable about it. Maybe I'm searching the wrong way, but anyways.. here is my question:

      How is it possible to rewrite the URLs, that I'll get a *.php ending?
      Example:
      https://www.mysite.de/urlsegment/ -> https://www.mysite.de/urlsegment.php
      https://www.mysite.de/urlsegment/urlsegment/ -> https://www.mysite.de/urlsegment/urlsegment.php
      Because I've read a lot about "Why do you wanna do this or have that?" – here my answer for that in advance:
      I've built a processwire installation inside or around an existing website. Therefore, we want to keep the existing *.php Google entries. Sure, we could redirect via 301 Redirect, but would prefer to keep the *.php ending.
      If you have further questions, please do not hesitate to ask.
      Thank you in advance for your help.

      Best regards
      ce90
×
×
  • Create New...