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

christian_H's avatar

Creating Redirect Rules in forge that redirect to a different site

Hey folks, I'm trying to use the redirects tab in forge to redirect users from an old site to a new one. Honestly, I can't really find much documentation for this regarding Forge, other than this twitter post (https://twitter.com/laravelphp/status/967060155564199937?lang=en) I can't find much about this at all. Is it possible to use this tool to redirect from one site to another, or is it just for redirecting pages within your site?

I've tried to set up a redirect from my old site to a new site, for example I want to redirect my users from old.site.com to new.site.com, but when I add a redirect rule using forge nothing happens. I'm making sure the rule is set to permanent, but I'm not getting any redirect. Is there another step I'm missing, or is what I'm trying to do here not possible using Forge's redirect rules (I know I can do it from editing the nginx file). Thanks very much!

Edit: I am able to redirect from one page in my site to another page, just not from site to site. Thanks

0 likes
7 replies
Cronix's avatar
Cronix
Best Answer
Level 67

Yeah, those settings are for individual urls, not site-wide.

In forge, go to the "old.site.com" "site details" settings page. Scroll down to the bottom of the page. There is a "files" dropdown button. Select "Edit Nginx Config" from it. You'll get a popup containing the current config.

This should be your site definition to redirect everything from old.site.com to new.site.com.

server {
        listen 80;
        listen [::]:80;
        server_name old.site.com;
        return 301 http://new.site.com$request_uri;
}

That will redirect all urls to old.site.name to new.site.name, including any parameters. So, http://old.site.com/something/else would redirect to http://new.site.com/something/else

Instead of deleting everything that currently exists in the config for that site, I would comment out each line with a # at the beginning of the line, just in case there is a problem. Or better, if you know how, backup that config file before editing (via ssh).

7 likes
christian_H's avatar

Thanks @Cronix, guess that would have been too easy to be true. I've got a copy saved so time to jump in I guess, thanks for the advice!

christian_H's avatar

@Cronix sorry to bug you, but is there any other steps to take after editing the Nginx config file? I've updated and saved it but I'm not getting the redirect, could be something else going on with our servers but I wanted to make sure I didn't need to do anything else before it would take effect.

Cronix's avatar

Is it a regular domain or ssl?

1 like
christian_H's avatar

They're both ssl, what I've got looks like this just with the actual sites changed:

server {
    listen 80;
    listen [::]:80;
    server_name www.site.com;
    return 301 https://new.site.com$request_uri;
}

Is it possible that returning https is what's throwing it off? My new site automatically redirects to https so maybe I should just return http

Edit: Well, I tried having it return http://new.site.com$request_uri; but still not getting any redirect.

Cronix's avatar

I was going to suggest listening to both 80 and 443 ports if it was ssl.

Is that server block listed as the first thing in the nginx config?

1 like
christian_H's avatar

@Cronix, turns out the issue was caused by something a co-worker had set up on the other server, not anything with the nginx file. Thank you so much for your help dude, I really appreciate it!

Please or to participate in this conversation.