Any way to set up a custom route?

For example:
Anyone visiting

mysite.com/forward/abcd1234

should get redirected to:

forward.mysite.com/abcd1234

where abcd1234 is a variable component.

mysite.com is the domain that I’ll be forwarding to Softr, but there are forwarder routes on my existing website that I don’t want to disturb. I’ve set up a separate subdomain for those, now I need to ensure that the links don’t break.

Hi @kt1 and welcome to the community!

I’m not sure I understand exactly what you’re looking for, but I’ll take a wild stab that it could be the URL Redirects feature.

If that’s not it, can you please explain in more detail exactly what you are trying to do in Softr?

1 Like

The URL redirects feature enables me to redirect one internal route to another internal route.
As I tried to explain using the examples, I want to forward routes with a custom path component to another subdomain entirely.

Still hoping for more details. (There are others on this board who are better at guessing than me, perhaps they will chime in!)

Let me try.
Let’s say mysite.com is the domain that I’m planning to use for my Softr site. It is currently pointing to my own servers, where I have custom routing set up to handle any URL that follows the mysite.com/forward/<any_variable_here> pattern. Such links correspond to custom pages that generate dynamic content based on the variable in the URL. When I change the domain to Softr, I don’t want to break the routing logic for these links of my app, so I have set up a subdomain forward.mysite.com and pointed it to my own server, which will handle the links that previously followed the mysite.com/forward pattern.

So now I just have to find a way for Softr to forward the old routes to the new ones. Here are some more examples:

mysite.com/forward/abcd1234 should be routed to forward.mysite.com/abcd1234

mysite.com/forward/wxyz7890 should be routed to forward.mysite.com/wxyz7890

mysite.com/forward/foobar should be routed to forward.mysite.com/foobar

OK, I get it now.

There are a couple of different ways to solve this.

You didn’t say whether you have a specific list of redirects, or whether you need to create a rule where mysite.com/forward/<anything> will properly redirect.

The first thing I would try is to approach Softr support (use the chat feature in the studio) and ask them if they can set this up for you. I know that they have the ability to load in a long list of specific redirects, but if you are looking for a redirect rule, they may not be able to help with that.

The other way you might be able to get this to work is to create a Softr page for each redirect, and then write some custom code that runs on that page and does the redirect for you in JavaScript.

Finally, there might be a way to get this to work using the custom 404 page feature in Softr, where if the URL starts with mysite.com/forward and the page does not exist in Softr, the 404 page runs custom code to do the redirect.

So the next question is whether you have a defined list of redirects (and if so, how long it is), or whether you need it to be a rule.

1 Like

Thanks. It has to be a rule because I need it for mysite.com/forward/<anything>.

I’ve tried all the options you mentioned except for the last one.

This doesn’t work because if I make a page /forward in Softr, it’s only displayed if the user goes to mysite.com/forward and does not work for subpaths like mysite.com/forward/<something> (this goes to a 404 page).

What is the way to set up the 404 page to do custom redirects?

The docs for the 404 page are here: How to set up a 404 Page - Softr Docs

But there’s another question, which is whether custom code on that page can get the original URL that the user accessed. Checking now…

Thanks @dcoletta for nudging me in the 404 direction, I figured it out. :slight_smile:

I made a custom code block on the 404 page and added this:

<script>
var path = window.location.pathname;

if (path.startsWith("/forward/")) {
    var path_part = path.substring(8);
    window.location.replace("https://forward.mysite.com" + path_part)
}
</script>
1 Like

OK good, that answers my question about whether you can access the original URL.