Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document a conditional redirect in .htaccess in a suitable place. #22

Open
janwillemstegink opened this issue Feb 3, 2025 · 1 comment

Comments

@janwillemstegink
Copy link

janwillemstegink commented Feb 3, 2025

Before internet.nl is testing both without and with www, some practical knowledge may help.

For advanced conditional logic, Apache 2.4 introduced Apache Expression Language (mod_expr).
The first URL via HTTPS can be refreshed, as security headers strictly require, with a conditional redirect.

Redirect in .htaccess if www:
<If "%{HTTP_HOST} =~ /^www.example.com$/">
# Redirect 302 / https://example.com/

Redirect in .htaccess if no www:
<If "! (%{HTTP_HOST} =~ /^www.example.com$/)">
Redirect 302 / https://www.example.com/
</If

My suggestion is to document a conditional redirect in .htaccess in a suitable place.

This issue has been edited for these notes:

  • The escaped dot for Apache configuration is not visible in HTML, therefore also a screenshot;
  • The Redirect directive may not work within . Maybe use RedirectMatch or Rewrite some way;
  • An example for Nginx would complete.

Image

@bwbroersma
Copy link
Collaborator

Probably the toolbox-wiki is the best location for configuration samples.
However domain canonicalization issues are not in scope of Internet.nl, in the sense that these - to my knowledge - are not listed in a 'comply or explain', NCSC guideline or other Best Current Practices.

@baknu baknu transferred this issue from internetstandards/Internet.nl Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants