There are many ways to redirect www to non-www and vice versa on Nginx. In this article, HOSTVN will guide you the simplest way to do this on Nginx.
Redirect www to non-www and vice versa on Nginx
1. Redirect non-www to www
To redirect the website url from the form domain.com to www.domain.com You can use the configuration Nginx as follows:
server { server_name "~ ^ (?! www .). *" ; return 301 $scheme://www.$host$request_uri; } |
2. Redirect www to no www
To redirect the website url from the form www.domain.com to domain.com You can use the configuration Nginx as follows:
server { server_name "~ ^ www . (. *) $" ; return 301 $scheme:// $ 1 $ request_uri; } |
In addition to the above 2 ways, there are several WordPress plugins that can be handled using PHP code. But for performance reasons, HOSTVN It is not recommended to use plugins, please configure instead Nginx!
3. Conclusion
In this article HOSTVN I showed you how to redirect www to n without www and vice versa on WordPress. If you have any comments you can leave a comment below. Also you can see more instructions for installing Fail2Ban on CentOS 7 against bruteforce attack.
0 Comments