Score:0

NGINX: redirect root / -> /new/path wihtout breaking the page

in flag

when I use this in my server-block:

    if ($http_host = "portaldemo.mydomian.tld/") {
       return 301 https://portaldemo.mydomian.tld/new/path/;
    }

I get redirected from my root-domain to the subpage I want. But my app doesn't work correctly anymore. How can I redirect without breaking the page?

us flag
`$http_host` variable contains only the value of HTTP `Host` header and that does not contain any path component. Your example is wrong. Please provide more details what your app is, and please show the full configuration of nginx as shown by `nginx -T` command.
Score:0
vn flag

As mentioned in the comments - there isnt enough information about the application you're using to provide a definitive answer; however, this is usually the result of the web application not being aware that it is being served from a subdirectory.

Though the resource you requested is loading, there will be other components of the application (such as css, js, images) that are requested when loading the initial resources but still reference the previous path.

For example: A web page at /index.html is moved to /subdir/index.html with the following source

<html>
<head>
<title>mysite</title>
<link rel="stylesheet" type="text/css" href="/mystyles.css">
...snip...

The page index.html will load from /subdir/index.html however the requested resources at /mystyles.css is no longer at that location but instead /subdir/mystyles.css

If the web application has these values hardcoded in then they will need to be manually changed to match the new address.

If the backend is dynamic in that it can globally configure the prefix (like wordpress) then you can update the prefix to /subdir/ and the site should behave as it did previously. will load when you request the resource but the

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.