Score:2

How do I redirect a specific URL/ROUTE/PATH/LOCATION to another?

mk flag
Anm

Say my client (current device) wants to connect to a URL, say foo.bar.com/spam/eggs/123, how do I serve or redirect to another specified URL, say 127.0.0.1:8080, and prevent the client from reaching foo.bar.com/spam/eggs/123?

What software can I use?

Saxtheowl avatar
by flag
What operating system are you using ? please provide more information
Anm avatar
mk flag
Anm
I am using linux @Saxtheowl
Score:4
in flag

If I understand your setup, you have some external domain, example.com, controlled by a 3rd party, with a website running on it, controlled by someone else. You want to allow access to that site generally, but block certain URLs.

There are a few solutions to this; they all boil down to some sort of proxy server. You would proxy web traffic via this proxy server and have a block/redirect list configured in it, which would deal with predefined exceptions.

One free solution is squid caching proxy, which does have redirectors support (here are details in the documentation - https://wiki.squid-cache.org/Features/Redirectors). Do note though that it's very much not trivial to set this up correctly and maintain it. No disrespect, but based on the fact that you had to ask this question, I suspect you may struggle to do this successfully.

Score:1
by flag

You should use a reverse proxy like Nginx first install it sudo apt-get install nginx then go to the configuration file at /etc/nginx/sites-available/foo.bar.conf and put this inside:

server {
    listen 80;
    server_name foo.bar.com;

    location /spam/eggs/123 {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

then enable it with ln -s /etc/nginx/sites-available/foo.bar.conf /etc/nginx/sites-enabled/

With this configuration, when a client tries to connect to foo.bar.com/spam/eggs/123, Nginx will redirect the request to http://127.0.0.1:8080

then reload Nginx sudo systemctl reload nginx

Nikita Kipriyanov avatar
za flag
it is always better not to modify existing distribution-installed files it possible, but to add your own alongside into the configuration drop directory (so a package update won't disturb it, for example). In this case, better put this content into `/etc/nginx/sites-avaliable/foo.bar.conf` and enable it with `ln -s /etc/nginx/sites-available/foo.bar.conf /etc/nginx/sites-enabled/`. Also restart is not required, reload is enough.
Anm avatar
mk flag
Anm
This did not work for me, isnt nginx a reverse proxy? foo.bar.com is not owned by me but I would like to redirect a specific location on it, and allow the rest
sa flag
I downvoted this because it doesn't answer the question and doesn't work.
I sit in a Tesla and translated this thread with Ai:

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.