Skip to main content
Share Your Experience: Take the 2024 Developer Survey
146 votes

Nginx reverse proxy + URL rewrite

The absolute most correct way and best practice is usually as follows: location /foo/ { proxy_pass http://localhost:3200/; # note the trailing slash! } Note the dire importance of the trailing ...
cnst's user avatar
  • 14.3k
122 votes
Accepted

Best way to redirect all HTTP to HTTPS in IIS

The IIS URL Rewrite Module 2.1 for IIS7+ may be your friend. The module can be downloaded from IIS URL Rewrite. Using the URL Rewrite Module and URL Rewrite Module 2.0 Configuration Reference explain ...
sippybear's user avatar
  • 3,287
20 votes
Accepted

How to stop nginx 301 auto redirect when trailing slash is not in URI?

There is a special kind of processing for this scenario, as per the docs: If a location is defined by a prefix string that ends with the slash character, and requests are processed by one of ...
famousgarkin's user avatar
18 votes

View the SSL certificate of a page that immediately redirects to another

In Firefox 57, if you open the Developer Tools and go to the Network tab: Make sure Persist Logs is checked Visit the URL of interest Click on the top row (i.e., the one corresponding to the request ...
mpavey's user avatar
  • 413
9 votes

NGINX 301 and 302 serving small nginx document body. Any way to remove this behaviour?

Yes, you can ABSOLUTELY do it with NGINX! Simply install an exception handler, a.k.a. error_page, to post-process required responses. Make sure to set it in such a way as to prevent the error page ...
cnst's user avatar
  • 14.3k
8 votes

Best way to redirect all HTTP to HTTPS in IIS

My research shows that this might be a better way to the redirect: <rewrite> <rules> <rule name="http to https" stopProcessing="true"> <match url="(.*)" /&...
Fallen Angel's user avatar
6 votes
Accepted

NGINX redirect if user agent contains XYZ

With ~* you are attempting to loosely match the string, but your regex is ^XYZ$ which says match only if it starts with XYZ and only if it ends in XYZ. That's not loose at all. You are kind of ...
JayMcTee's user avatar
  • 4,031
6 votes
Accepted

SSL certificate error in domain redirection

You must provide a valid certificate when the browser visits https://<domain-s>, the certificate check is performed before processing the page content/redirects/... and this is by design. If you ...
Swisstone's user avatar
  • 6,915
5 votes
Accepted

Using Apache RedirectPermanent to send all requests to a specific subfolder

Redirect is not the correct one to use for what you seek. Redirect redirects "all" and "appends that all" to the destination, but you want a final single destination, so.. use this instead: ...
Daniel Ferradal's user avatar
5 votes
Accepted

nginx rewrite from www to non-www

The $server_name refers to the server name you have defined in the virtual host block. Therefore your additional block causes a redirect cycle redirecting back to itself. You have to use a literal ...
Tero Kilkanen's user avatar
5 votes
Accepted

Redirecting from www to no www in nginx reverse proxy

The preferred setup for a web server handling http://example.com, https://example.com, http://www.example.com and https://www.example.com is the following when the example.com domain and https are ...
Tero Kilkanen's user avatar
5 votes
Accepted

Have nginx redirect everything to https except one directory

it returns addresses that include "_". server_name _; location /.secret { return http://$server_name$request_uri; } $server_name returns assigned server_name to the server block, which ...
mforsetti's user avatar
  • 2,786
5 votes

.htaccess - Redirect all URLs with one exception

As mod_alias is recommended for simple redirects, here's the solution with mod_alias: # Specific redirects: Redirect 301 /old-prefix https://www.example.com/ Redirect 301 /another-old-prefix/ https://...
Esa Jokinen's user avatar
  • 50.1k
4 votes
Accepted

How to forward all http requests to https without breaking letsencrypt with nginx

My working configuration for this is: server { listen 80; listen [::]:80; server_name example.com www.example.com; root /srv/www/empty; include includes/...
Michael Hampton's user avatar
4 votes

.htaccess 301 redirect for URL ignoring its parameters

If you want to simply ignore all parameters, then you can still use a standard Redirect, because it is prefix matching and does not match against the query string anyway. For example: Redirect 301 /...
MrWhite's user avatar
  • 13.1k
4 votes
Accepted

.htaccess 301 redirect for URL ignoring its parameters

That's where you should use a RedirectMatch directive with regex matching instead of the plain Redirect. Maybe something along the lines of: RedirectMatch 301 "/slug1/slug2/slug3(.*)$" "/slug4"
HBruijn's user avatar
  • 80.7k
4 votes

nginx downloads empty file when requested on port 80 (instead of redirecting to port 443)

Adding this simply because this is one of the only pages that shows up for a google search of the related topic. I had the same issue and finally found that the resolution was the same as you've ...
Winston Krauss's user avatar
4 votes

nginx downloads empty file when requested on port 80 (instead of redirecting to port 443)

I've solved the problem. It was a config file from a subdomain which had a own root-directory configured. The config file from the subdomain had listen 80 http2; listen [::]:80 http2 which affected ...
Unkn0wn0x's user avatar
4 votes
Accepted

Modify Nginx 301 response body

There's a great post about custom error pages at the following URL. The following is an abbreviated version of how it can be used to remove nginx branding from the 301 and 302 HTTP responses. One ...
phbits's user avatar
  • 226
4 votes

DNS redirect to website directory

No, DNS is not aware of http, so you can't point it at a server based on URL. You can point DNS at a load balancer, such as Nginx, and have it proxy the request to other servers. If you want ...
Tim's user avatar
  • 33k
4 votes

Redirecting from https to http?

The 301 redirect most probably comes from your backend server in the docker container. It is configured with the http://... url. Configure your application server in the container with the proper URL.
Gerald Schneider's user avatar
4 votes
Accepted

How can I redirect domain A to domain B without hosting, using only DNS records?

Redirects cannot be done with DNS only. However, some providers have HTTP redirect services that are configured via same interface as DNS. These support only HTTP. HTTPS support requires valid ...
Tero Kilkanen's user avatar
4 votes
Accepted

.htaccess - Redirect all URLs with one exception

You are mixing mod_rewrite (RewriteCond, RewriteRule) and mod_alias (Redirect, RedirectMatch). The stray mod_rewrite RewriteCond directive will not do anything here. This directive only applies to the ...
MrWhite's user avatar
  • 13.1k
3 votes
Accepted

Redirecting via 301 subdomain to URI/URL configuration error in NGINX

Follow best practices and use the return directive: server { server_name nginx.somedomain.com; return 301 http://nginx.somedomain.com/sample/redirection.html; }
gxx's user avatar
  • 5,661
3 votes

Apache 2.4 restrict URL to certain IPs

For Apache 2.4, you can use <RequireAny>. You can do it in a vhost or an .htaccess file.... SetEnvIF IP xxx.xxx.xxx.xxx AllowThisIP # Or X-Real-IP SetEnvIF IP yyy.yyy.yyy.yyy AllowThisIP <...
MontyThreeCard's user avatar
3 votes
Accepted

Server hacked, 301 redirect, domain lost?

Your domain is not lost, but your browser (and those of your users) will cache the redirect, possibly indefinitely. You can clear your own browser cache yourself, but this won't fix issues your ...
Sven's user avatar
  • 99.6k
3 votes
Accepted

EC2 with elastic IP & Route53 DNS - Domain is resolving to incorrect public DNS

Looking into the issue, doing a nslookup on the domain gives me: Name: www.racheldoesfestivals.com Address: 34.197.64.48 This is an IP belonging to AWS, so I'm assuming this is going to the ...
KHobbits's user avatar
  • 1,188
3 votes

CNAME redirect to external https url

I was expecting that the CNAME entry would "ignore" the server at start.com. The request should go directly to root.com, shouldn't it? False expectation, and discussed here over and over again: ...
Esa Jokinen's user avatar
  • 50.1k
3 votes
Accepted

NGINX 301 list of redirects SEO

I don't know of a better way, although I too would like to, but your configuration is broken due to missing ; after return directive. location = /programs-services/ { return 301 https://www.somesite....
virullius's user avatar
  • 1,058
3 votes

How to redirect specific pages in htaccess, and all other redirect to the homepage?

To match all remaining pages and redirect to the home page of the new site you'll need to use the RedirectMatch directive (also from mod_alias). For example: RedirectMatch 301 .* https://newdomain....
MrWhite's user avatar
  • 13.1k

Only top scored, non community-wiki answers of a minimum length are eligible