Skip to content

fix(backdrop): Fix nginx config for routes conflicting with directories, fixes #7495 - #7496

Merged
rfay merged 7 commits into
ddev:mainfrom
rfay:20250731_rfay_fix_webserver_directory_conflicts
Aug 20, 2025
Merged

rfay merged 7 commits into
ddev:mainfrom
rfay:20250731_rfay_fix_webserver_directory_conflicts

Conversation

@rfay

@rfay rfay commented Jul 31, 2025 •

Copy link
Copy Markdown
Member

The Issue

Fix nginx configuration for Backdrop CMS to handle routes that conflict with existing directory names, specifically the /modules route vs modules/ directory.

This is critical for working locally with backdropcms.org, which has those routes.

When Backdrop CMS defines a route (like /modules) that matches an existing directory name (modules/ directory), the nginx configuration causes HTTP 403 Forbidden errors due to directory listing attempts.

This fix is Backdrop-only to minimize risk while addressing the specific issue reported by the Backdrop community.

How This PR Solves The Issue

nginx configuration for Backdrop CMS:

  • Add specific location block for common Backdrop routes (/modules, /themes, /sites) that conflict with directories
  • Use try_files /nonexistent @rewrite to force these routes to the CMS handler instead of attempting directory access
  • Update main location block to use @rewrite for consistency
  • Improve @rewrite handler to pass query string properly for Backdrop

Manual Testing Instructions

  1. Create a DDEV project with Backdrop CMS:
    ddev config --project-type=backdrop
    ddev start
  2. Create a page at the /modules route in Backdrop CMS admin
  3. Test: curl -I https://project.ddev.site/modules
  4. Expected: HTTP 200 from CMS route (not 403 Forbidden)
  5. Verify file serving still works: curl -I https://project.ddev.site/files/image.png
  6. Verify directory requests handled properly: curl -I https://project.ddev.site/files/

Automated Testing Overview

This change maintains backward compatibility - existing functionality is preserved while fixing the directory conflict issue. The change is limited to Backdrop CMS configuration only, minimizing risk to other project types.

Release/Deployment Notes

  • This fix only affects DDEV Backdrop CMS projects
  • Maintains security (no directory listings) while allowing proper CMS routing
  • Preserves existing behavior for all other project types
  • Conservative approach reduces risk while addressing the specific reported issue

🤖 Generated with Claude Code (https://claude.ai/code)

@github-actions

github-actions Bot commented Jul 31, 2025 •

Copy link
Copy Markdown

@rfay

rfay commented Aug 1, 2025

Copy link
Copy Markdown
Member Author

I think this PR in general may be a failure, but this nginx-site.conf rule is probably decent for people who encounter this specific problem:

# Handle common CMS/framework routes that might conflict with physical directories
  location ~ ^/(modules|admin|api|content|themes|plugins|wp-admin|wp-content|wp-json|system|vendor|node_modules)/?$ {
      try_files /nonexistent /index.php?$query_string;
  }

  location / {
      absolute_redirect off;
      try_files $uri $uri/ /index.php?$query_string;
  }

@rfay
rfay force-pushed the 20250731_rfay_fix_webserver_directory_conflicts branch from 693fcc1 to 700747a Compare August 1, 2025 20:04
@rfay rfay added this to the v1.24.8 milestone Aug 13, 2025
rfay and others added 6 commits August 19, 2025 13:23
Remove problematic webserver directives that cause 403/redirect errors when CMS routes conflict with existing directory names.

## The Issue

- ddev#7495

When a CMS defines a route (like /modules) that matches an existing directory name (modules/ directory), the current webserver configurations cause issues:

- nginx configurations: Return HTTP 403 Forbidden errors due to directory listing attempts
- Apache configurations: Create unwanted HTTP 301 redirects to trailing slash versions

This affects every CMS and framework that DDEV supports when routes conflict with directory names.

## How This PR Solves The Issue

**nginx configurations (22 files updated):**
- Remove $uri/ from try_files directives to prevent directory listing attempts
- Change from: try_files $uri $uri/ /index.php?$query_string;
- Change to: try_files $uri /index.php?$query_string;

**Apache configurations (2 files updated):**
- Remove directory detection and trailing slash redirect rules
- Remove: RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
- Remove: RewriteRule ^(.+[^/])$ https://%{HTTP_HOST}$1/ [redirect,last]

## Manual Testing Instructions

1. Create a DDEV project with a CMS that has directory conflicts (e.g., Backdrop CMS with modules/ directory)
2. Create a page at the conflicting route (e.g., /modules) in the CMS
3. Test: curl -I https://project.ddev.site/modules
4. Expected: HTTP 200 from CMS route (not 403 Forbidden or unwanted redirects)
5. Verify file serving still works: curl -I https://project.ddev.site/files/image.png
6. Verify directory requests handled properly: curl -I https://project.ddev.site/files/

## Automated Testing Overview

This change maintains backward compatibility - existing functionality is preserved while fixing the directory conflict issue. No new tests are needed as this resolves existing problematic behavior without changing the intended functionality.

## Release/Deployment Notes

This fix affects all DDEV webserver configurations but maintains security (no directory listings) while allowing proper CMS routing. The change removes web server automatic directory selection behavior, but this is acceptable for modern CMS/framework architectures that handle their own routing.

🤖 Generated with Claude Code (https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Revert the wordpress nginx change, go back to upstream/main
- Back off of expectations in TestHttpsRedirection
@rfay rfay changed the title fix: Improve nginx and apache configs to work when there is a matching directory in filesystem, fixes #7495 fix(backdrop): Fix nginx config for routes conflicting with directories, fixes #7495 Aug 19, 2025
Remove nginx config changes from all other CMS types and keep only
the Backdrop-specific fix to address directory conflict issue reported
in ddev#7495. This conservative approach minimizes risk while solving the
specific problem for Backdrop CMS projects.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@rfay
rfay force-pushed the 20250731_rfay_fix_webserver_directory_conflicts branch from 700747a to 409fd37 Compare August 19, 2025 19:44
@rfay

rfay commented Aug 19, 2025

Copy link
Copy Markdown
Member Author

I felt like this was too large a change to be justified by one specific site's problem, so backed out everything but backdrop's usage.

@rfay
rfay marked this pull request as ready for review August 19, 2025 19:46
@rfay
rfay requested a review from a team as a code owner August 19, 2025 19:46
@rfay
rfay requested a review from stasadev August 19, 2025 19:46
@rfay

rfay commented Aug 19, 2025

Copy link
Copy Markdown
Member Author

@jenlampton it would be great if you could test this with your situation. Artifacts in #7496 (comment)

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a modules page and it worked. I also clicked on different links to confirm nothing else broke.

Looks good to me.

@rfay
rfay merged commit 06209dd into ddev:main Aug 20, 2025
@rfay
rfay deleted the 20250731_rfay_fix_webserver_directory_conflicts branch August 20, 2025 15:58
@rfay rfay mentioned this pull request Sep 17, 2025
30 of 42 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants