Managing Redirects in Forge 0:00We've now set up our site, deployed our code, and run a couple of commands. Everything has been running great for a while now, but our marketing team have come to us to suggest that we need to change the About Us page of our site to Company. Now, we don't want to maintain two routes in our application that render the same view, and we also don't want to lose SEO rankings for our About page. And remember, duplicated content is not SEO-friendly, so even if we could maintain two routes, we most certainly don't want to. Now, thankfully, we can create redirect rules for our site in Forge. So, if we go to the site page and go down to the Redirects panel here, we can see that Forge makes it super easy to manage these for us. Choosing Redirect Types 0:36So, if we go to the site page and go down to the Redirects panel here, we can see that Forge makes it super easy to manage these for us. We just need to provide three bits of information. Firstly, the From, which in this case would be About Us. The To is where we want to redirect to, which is Company. And then finally, the Redirect Type. Now, Forge allows us to do a temporary and permanent redirect. Temporary is a HTTP status code of 302, and permanent is 301. Now, these don't sound particularly different if you've never done anything with redirects, but a temporary redirect will mean that anytime a customer visits your website on this From page,Now, these don't sound particularly different if you've never done anything with redirects, but a temporary redirect will mean that anytime a customer visits your website on this From page, it will always hit your server to see where it needs to go. Now, this means you can change these redirects in the future, no problem. Now, a permanent redirect will mean that the browser caches where this redirect takes us to, and the next time we hit this page, the browser is going to skip hitting your server and go straight to this page instead. Okay, let's add this redirect rule, and we can see it's being added here. Now, if we visit our site and we go to our About Us page, we can see it's taken us straight to the Company page. Creating Regex Redirects 1:45Now, if we visit our site and we go to our About Us page, we can see it's taken us straight to the Company page. Okay, so we've created a pretty simple rule here. We've gone from one static page to another static page, but we can also use this panel to create more advanced redirect rules. Let's switch back to our site. We can see here that we've now got product-info forward slash a product ID, and we can see when we view this page, showing all product URL number two. If we change these, we can see that we've also got three, and it's dynamic here. In this case, we want to redirect to just simply product number three.If we change these, we can see that we've also got three, and it's dynamic here. In this case, we want to redirect to just simply product number three. We can do that by using a regular expression rule. To do that, we'll put in a caret product-info forward slash, and then we're going to create a capture group here, where we only capture digits between zero and nine, and we'll capture as many of them as we can. And we'll stop that rule when it hits anything other than what's in this capture group. And we're going to redirect to simply product, and then dollar one. The dollar one here will evaluate to whatever this capture group is here.And we're going to redirect to simply product, and then dollar one. The dollar one here will evaluate to whatever this capture group is here. We'll create a temporary redirect rule for the sake of testing this. Add that. We can see it's being installed. Okay. If we switch back to our site, we should now go from product-info to simply product. There we go. We've redirected. And we can test this by going to another URL, product URL 99. Editing Nginx Redirect Rules 3:09We've redirected. And we can test this by going to another URL, product URL 99. Yep. We've completely redirected here. Now, in Nginx, there are multiple ways of creating redirect rules. And actually, you can go even more advanced than what we've created here. To do that, though, we will need to SSH into our server and manually create the rule. So, Forge stores these redirect rules in forward slash etc, forward slash nginx, forge-conf, and then the name of our site, and then server. If we redirect, we can see here that we've got this redirect rules configuration file.forge-conf, and then the name of our site, and then server. If we redirect, we can see here that we've got this redirect rules configuration file. If we cap the contents of this, we can see our rules have been created here. Now, you don't want to write directly to this file because Forge is going to rebuild this anytime one of the redirect rules is updated or created. Instead, you would maybe want to create your own custom redirect rules file and put in the contents of this here. Of course, you'll notice that the directory is not writable, and that's because we're currently logged in as the Forge user. So, we would actually need to do sudo custom-redirect-rules.com. Finding Advanced Redirect Docs 4:14and that's because we're currently logged in as the Forge user. So, we would actually need to do sudo custom-redirect-rules.com. Of course, if you're looking to get into even more advanced rules here, it would be worth checking out the nginx-reroute-rule documentation, because this completely explains everything you need to know, including how you can use things like the user agent and cookies to redirect further.