G
G
Galdar Turin2020-05-20 09:06:38
Nginx
Galdar Turin, 2020-05-20 09:06:38

How to redirect to another directory?

There is such a link https://domain.ru/bx/ , which redirects to the required directory /application/dist/ , index.html opens in it , but all connected scripts in this file try to access https://domain.ru / , but you need to go to https://domain.ru/bx/ . Adding https://domain.ru/bx/ to src is not an option.
What are the configuration options in NGINX to send a request to https://domain.ru/bx/ ?

location ^~ /application/ {
    return 403;

    internal;

    location ~ ^/application/dist/ {
      index index.html index.hml;
    }

  }
  
  location /bx/ {
    rewrite ^/bx/$ /application/dist/ last;
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2020-05-20
@gromdron

nginx will not help you much here: review the connection of scripts on the page.
IF the scripts are included in a relative path and start with a slash (/src.js), then such paths will be searched from the site root, not your directory.
Of course, you can try to use the base tag, but it is unlikely to help here.

D
dodo512, 2020-05-20
@dodo512

location /bx/ {
    rewrite ^/bx/$ /application/dist/ last;
}

Here it is better to use alias
location /bx/ {
    index index.html;
    alias /var/www/application/dist/;
}

And in index.html, specify the path to the scripts already with /bx/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question