[OPNWAF] Per virtual server option: redirect non-www to www

Open
#5,932 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend, web-dev

Research direction

Start by locating the OPNWAF virtual server modal and the code that generates gateway_vhost.conf; the issue names the existing RewriteRule and the desired behavior. Trace how virtual server options reach the generated configuration, then check the relevant plugin tests or validation path. Done when the per-server checkbox produces the requested single redirect when enabled and preserves the current rule when disabled.

Written by the indexing model from the issue text.

Description

support

Important notices
Before you add a new report, we ask you kindly to acknowledge the following:

Is your feature request related to a problem? Please describe.

If the "HTTP to HTTPS" option is enabled, the OPNWAF plugin redirects http://example.com to https://example.com, but not to the canonical https://www.example.com. The non-www to www redirect currently has to be done by the web server itself (e.g. via .htaccess), resulting in two consecutive redirects before reaching the canonical host.

Describe the solution you'd like

A per-virtual-server checkbox in the virtual server modal: "Redirect non-www to www". When enabled, requests to http://example.com should be redirected in a single redirect to https://www.example.com.

In the generated gateway_vhost.conf, the virtual host currently contains:

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

With the option enabled it should instead contain:

RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Describe alternatives you've considered

Handling the non-www to www redirect from the web server itself via .htaccess, which works but requires a second redirect and moves canonicalization away from the edge.

Additional context

None.

Dominant language
PHP
Stars
1.2k
Forks
926
Avg merge
1d 10h
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opnsense/plugins

All issues in opnsense/plugins

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.