How to redirect www to non www for the domain using Nginx webserver?

nginx + virtualmin+drupal 10

I need to redirect www.example.com to example.com but i cant because when i change in .htacces (drupal file) no results. How to change in Virtualmin ? Thanks

SYSTEM INFORMATION
OS type and version ubuntu 22.10
Webmin version 2.520
Virtualmin version 7.50.0 GPL
Webserver version Nginx
Related packages SUGGESTED

Virtualmin -> Web Configuration -> Web Options # Redirect All Requests to SSL Site = Yes

.htaccess is the garbage you get/use with Apache nothing to do with Nginx

1 Like

Is activated but I asked not about this i need to redirect my domen with www –https://www.examaples.com to non ---- https://examaples.com. Normaly i can do in .htaccess in drupal file but … i have nginx

@Jamie, do you remember implementing “Redirect to canonical domain” option for Nginx systems?

Yes that should work, and it’s implemented using redirects in nginx.conf rather than the .htaccess files.

Cool! But could you point me to the code where it’s done, both in Virtualmin and the Nginx plugin?

My apologies, since this capability depends on hostname-specific redirects it’s not currently implemented for Nginx.

2 Likes