Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
How to redirect to external site from directory (from url with this site)

On many my sites there is a tradition of making redirects through an internal directory. It looks so that the external link to Yandex from site.ru looks like this:

https://site.ru/out/https://ya.ru

This url will 301 redirect to https://ya.ru.

In apache i do this in .htaccess:

RedirectMatch 301 /out/(.*)$ 1.

Trying to rewrite for nginx, doing that:

rewrite /out/(.*) $1 permanent;

But it redirecting to https://site.ru/ya.ru, not to https://ya.ru.

I add this config to my.conf (i created this file in /etc/nginx) and do «include /etc/nginx/my.conf;» (in server{} of course) in all conf files of my sites.

Help me please with the config, I can't figure it out.(

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Part of the problem is that rewrite uses a normalised URI which has folded multiple consecutive /s into a single /. It is better to use the original request which is stored in $request_uri.

One possible solution is to use a map to extract the embedded URL. For example:

map $request_uri $redirect {
    default 0;
    ~^/out/(?<out>.*)$ $out;
}

server {
    ...
    if ($redirect) { return 301 $redirect; }
    ...
}

See this document for details, and this caution on the use of if.


You can achieve the same thing without using a map using:

if ($request_uri ~ ^/out/(.*)$) { return 301 $1; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!