Question

Redirecting www to nonwww version on ServerPilot

Hi,

I am totally new to having my own server. So please bear with me if my questions are too simple for some of you.

I used ServerPilot to set everything up. Everything works great, but my www version doesn’t redirect to non www.

I have this code in my .htaccess file (which worked perfectly on shared hosting before - I assume because they were using Apache):

RewriteCond %{HTTP_HOST} ^www.example.com.se$ [NC]
RewriteRule ^(.*)$ http://example.com.se/$1 [R=301,L]

Now, my research shows that serverpilot uses nginx and that the above code doesn’t work for nginx. But then I read a guide on serverpilot that says they use nginx along with apache and that the htaccess code should work. But it is not working currently.

So I am very confused. I would appreciate any help on how to achieve this.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Thanks this just helped me now. I guess I was using the old code, non-nginx code and it never caused an issue until just an hour ago. :O

But it’s all up and running now that I used that code instead. It was redirecting to /srv/… over and over in the URL box

Hi,

What you’re doing as well as those rewrite rules look correct. ServerPilot configures Nginx as a reverse proxy in front of Apache so you still can use .htaccess files exactly as you’re doing.

Please check to make sure you’ve added those RewriteRule/RewriteCond lines to the very top of your .htaccess file. If you’ve added them below other stuff (for example, below the WordPress stuff), they won’t work reliably.