Drupal core .htaccess is redirecting to index.php

Created on 9 August 2023, over 1 year ago
Updated 10 August 2023, over 1 year ago

Problem/Motivation

I am using the core .htaccess file with no changes as it is compliant with with RFC 5785 and allows the challenge. The only change we have is to enforce http -> https

However, when I try to access the URL via curl, I'm being redirected to the index.php of the site because of the following section.

  # Pass all requests not referring directly to files in the filesystem to
  # index.php.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

I'm no expert at this, but I think this is happening because the challenge is not an actual file on the webserver.

Steps to reproduce

- Drupal 9 site with this module
- Configure a challenge
- Plain .htaccess from core with no changes
- request the challenge over http

❯ curl -k -L -v http://mysite.be/.well-known/acme-challenge/123456 2>&1 | egrep "^> (Host:|GET)"

> GET /.well-known/acme-challenge/123456 HTTP/1.1
> Host: mysite.be
> GET /index.php HTTP/2
> Host: mysite.be
> GET / HTTP/2
> Host: mysite.be

Proposed resolution

Changing this to the following solves the issue.

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  # Don't redirect for .well-known requests because we use the letsencrypt_challenge module.
  RewriteCond %{REQUEST_URI} !^\/\.well-known\/.*$
  RewriteRule ^ index.php [L]

If this is the way to go, I think we should create a documentation page explaining the steps needed for Drupal 8+

Remaining tasks

Create documentation + readme?

💬 Support request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇧🇪Belgium BramDriesen Belgium 🇧🇪

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @BramDriesen
  • Status changed to Closed: works as designed over 1 year ago
  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    Not sure where my head was when creating this issue. But the request should go to drupal...

Production build 0.71.5 2024