Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

whitea2's avatar

Is it possible to have 2 sites (1 www and 1 root) with Forge?

I have my site created with Forge at domain.com.

I have a staging site setup with Forge on the same server at staging.domain.com and have an A record with my DNS provider (Cloudflare) to point to the IP of my server.

This works great.

I added another site with Forge on my server at www.domain.com and created an A record similarly to staging.

However, if I visit www.domain.com, I automatically get redirected to domain.com with a status code of 301.

Why does this work for staging but not www?

0 likes
9 replies
Cronix's avatar

You need to edit the nginx config for domain.com. There is a www redirect to non-www rewrite in there. Something like

server_name www.domain.com;

return 301 https://domain.com$request_uri;
1 like
whitea2's avatar

Thanks @Cronix for the suggestion. Unfortunately, there are no return statements (or redirects) in the nginx config. I checked the config for domain.com and staging.domain.com.

I have also replaced the A records with CNAME records hoping that could resolve it but it did not.

Here are the configs for nginx:

domain.com

server_name .domain.com;
root /home/forge/domain.com/public;

staging.domain.com

server_name .staging.domain.com;
root /home/forge/staging.domain.com/public;

www.domain.com

server_name www.domain.com;
root /home/forge/www.domain.com/public;
fabricecw's avatar
Level 7

@awhite did you enable Let's encrypt or another SSL cert? Forge automatically adds the www subdomain into the "before" nginx configuration per default. You can checkout the config file in /etc/nginx/forge-conf/<<your site>>/before.

1 like
whitea2's avatar

@fabricecw that's exactly it, thank you so much!

I found

server_name www.domain.com;
return 301 https://domain.com$request_uri;

in the /etc/nginx/forge-conf/<<your site>>/before/ssl_redirect.conf

Thank you and @Cronix for the help!

whitea2's avatar

As a quick follow up, is it safe to edit the ssl_redirect.conf and how did it get that configuration?

fabricecw's avatar

I think the ssl_redirect.conf is auto-generated when activating a certificate. Have you removed the "www" form the Let's Encrypt certificate?

whitea2's avatar

Yes, I noticed the same auto-generation when activating a certificate. I imported a certificate and it included 'www' so maybe that's how the configuration was created.

Rather than generating new certificates (1 for domain.com, 1 for staging.domain.com and 1 for www.domain.com), I simply commented out the redirect in each ssl_redirect.conf file.

I'm not sure of the pros/cons of 1 aggregated certificate vs. individual ones. My approach seems a little hacky so maybe I'll swap to individual certificates over the weekend.

Cronix's avatar

Did you contact Forge support? They may have better guidance.

1 like
whitea2's avatar

No, and oddly that didn't occur to me. Thanks for the suggestion. If I learn anything helpful, I'll post back.

Please or to participate in this conversation.