252
votes
Nginx reverse proxy + URL rewrite
Simple location prefix matching works for this without using a rewrite rule as long as you specify a URI in the proxy_pass directive:
location /foo {
proxy_pass http://localhost:3200/;
}
Notice ...
- 2,631
133
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 ...
- 13.5k
117
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 ...
- 3,107
44
votes
Accepted
View the SSL certificate of a page that immediately redirects to another
Use openssl s_client piped to openssl x509:
$ openssl s_client -connect foo.example.com:443 < /dev/null | openssl x509 -text
(Add -servername foo.example.com to the s_client command if the server ...
- 109k
27
votes
Apache 2.4 restrict URL to certain IPs
The Order, Deny, and Allow options have been replaced in Apache 2.4 with
<Directory /var/www/mysite.com/htdocs/public>
Require all granted
</Directory>
You can explicitly restrict ...
- 391
24
votes
Is an SSL Cert needed for redirects?
A redirect from http://old.example.com to https://new.example.com does not require a certificate for old.example.com. But a redirect from https://old.example.com to https://new.example.com does.
If ...
- 816
17
votes
Is an SSL Cert needed for redirects?
Yes, you will need a new certificate if the redirection is done in a HTTP response (a 301 or 302 return code). If you don't the redirect will not work, visitors of the old domain will get an error the ...
- 1,837
17
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 ...
- 339
15
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 ...
- 353
10
votes
Restrict direct IP access to website
The answer could be much much simpler.
Just copy this into bottom of httpd.conf (usually located at /etc/httpd/conf)
<VirtualHost *:80>
ServerName localhost
Redirect 403 /
UseCanonicalName Off
...
- 201
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 ...
- 13.5k
8
votes
Accepted
Redirect loop when forcing SSL on Nginx server
As it stands, you're redirecting all traffic to https, which is good for http traffic, but for https traffic is quite pointless, and results in a redirection loop. What is happening right now is the ...
- 5,541
7
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="(.*)" /&...
- 79
6
votes
View the SSL certificate of a page that immediately redirects to another
Also, there is a graphical tool for Windows with detailed text trace: SSL Certificate Verifier Tool and tool description: Verifying The SSL Certificates with a tool and here is an example of how it ...
- 6,554
5
votes
Accepted
Is Apache RedirectMatch a good solution for these urls
Question 1: Is that a good idea or is there anything better?
Question 2: How to create rules to do this successfully with enough flexibility so I don't have to write many rules every time a new ...
- 4,295
5
votes
Accepted
Apache 2.4 restrict URL to certain IPs
Use Require [ip|host|env] to specify who has access to your vhost or location.
<Directory "/docroot">
Require ip 10.10.11.12
</Directory>
When it comes to ...
- 1,178
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:
...
- 2,340
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 ...
- 36.1k
5
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 ...
- 3,863
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 ...
- 36.1k
5
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 ...
- 6,510
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 ...
- 2,566
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://...
- 44.8k
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/...
- 241k
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 /...
- 12.2k
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 ...
- 31.2k
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.
- 21.8k
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 ...
- 12.2k
3
votes
Accepted
Nginx redirects not getting used
You have typos in your server_name directives.
You wrote coolthearth instead of cooltheearth in 3 places.
Testing the current setup with a typo gives :
curl -H "Host: coolthearth.org" "http://104....
- 13k
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
<...
- 131
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
301-redirect × 530nginx × 198
redirect × 169
.htaccess × 116
apache-2.2 × 77
mod-rewrite × 57
rewrite × 50
https × 44
apache-2.4 × 40
wordpress × 29
ssl × 28
apache2 × 23
http × 21
redirection × 18
domain-name-system × 17
iis × 17
virtualhost × 16
reverse-proxy × 14
linux × 10
httpd × 9
regex × 9
seo × 9
domain × 8
iis-7 × 8
haproxy × 8