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
30 votes
Accepted

Nginx multiple roots

The configuration has the usual problem that generally happens with nginx. That is, using root directive inside location block. Try using this configuration instead of your current location blocks: ...
25 votes

In Nginx, how can I rewrite all http requests to https while maintaining sub-domain?

Within the server block you can also do the following: # Force HTTPS connection. This rules is domain agnostic if ($scheme != "https") { rewrite ^ https://$host$uri permanent; }
  • 381
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 ...
24 votes
Accepted

Redirect all requests to HTTPS, except for one subdirectory

Try this: server { listen 80; server_name sub.domain.tld; server_tokens off; root /var/www/letsencrypt; location /.well-known { try_files $uri $uri/ =404; ...
22 votes
Accepted

How to mask a website URL transparently redirecting in Windows Server DNS

I am trying to setup a SharePoint intranet site in Office 365. Our DNS provider doesn't support masked redirects like GoDaddy does. Good for them! "Masked redirects", as GoDaddy calls it, are not a ...
  • 32.5k
19 votes

How do I redirect www to non-www in Route53?

You can also set a ALIAS for WWW to A record of domain.com: www.domain.com A ALIAS domain.com 300 so your final DNS entries would be as follows: domain.com A xxx.xxx.xxx.xxx 300 ...
17 votes

How to redirect root and only root via htaccess?

This should work just fine: RedirectMatch 301 ^/$ https://example.com/
  • 271
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
16 votes
Accepted

HAProxy: Redirect Root Site Root to Subsite

nlu is almost there, but the is_root ACL is a little bit off. Using path_beg will lead to any and all paths being matched, when really you only want to redirect requests with an empty path. Try ...
  • 9,260
15 votes

Redirect all http requests behind Amazon ELB to https without using if

Setup your AWS ELB mapping ELB:80 to instance:80 and ELB:443 to instance:1443. Bind nginx to listen on port 80 and 1443. Forward requests arriving at port 80 to port 443. Health check should be HTTP:...
15 votes

How to redirect HTTP to HTTPS on AWS Application Load Balancer?

As of July 2018, this is supported on application load balancers. Add/Edit your HTTP:80 listener Set the action to Redirect protocol: https port: 443 set the next dropdown to Original host, path, ...
  • 151
12 votes
Accepted

HTTP URL Redirection Command Line Trace

Try curl -v -L There are several tools, you can use from the command line, the most well known of which are curl and wget. With curl you can follow redirects using the flag -L; additionally, you want ...
  • 651
11 votes

In Nginx, how can I rewrite all http requests to https while maintaining sub-domain?

I posted a comment on the correct answer a long, long time ago with a very important correction, but I feel it is necessary to highlight this correction in its own answer. None of the previous answers ...
10 votes
Accepted

Can't remove forced HTTPS redirect from Nginx?

First of all, remove ssl on; Second, you had Strict-Transport-Security header and browsers remembered that for 2 years (as that commented out header says). Add it back with max-age=0 to remove the ...
  • 8,180
10 votes
Accepted

HSTS and double redirect

As noted on the HSTS preload list submission requirements: Redirect from HTTP to HTTPS on the same host, if you are listening on port 80. You need to redirect to the same host (ie. HTTP_HOST), not ...
  • 12.1k
10 votes
Accepted

Remove hashmark (#) from nginx url and redirect

You can't. The browser doesn't send anything after # to the nginx. The # indicates an URL fragment which is processed on a client only.
  • 8,347
9 votes

Apache 2.2 rewrite - Force all requests to index.html

Answer of @prix is good. I myself needed to add conditions so that normal resources (images & css) are served as normal: RewriteEngine On RewriteCond %{REQUEST_URI} !^/index.html$ RewriteCond %{...
  • 231
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
9 votes

Redirect all http requests behind Amazon ELB to https without using if

This solution uses conditional logic, but as the accepted answer suggests, I also think this is ok. Ref: https://stackoverflow.com/questions/4833238/nginx-conf-redirect-multiple-conditions Also, ...
9 votes
Accepted

Redirect with an exception

Simply like this: RedirectMatch ^/olduser/(?!exception/).* http://newuser.domain.com/ Instead of: Redirect permanent /olduser/ http://newuser.domain.com/ Will redirect all /olduser request exept ...
  • 3,033
9 votes
Accepted

Create Nginx redirect for a url with spaces (%20)

Use ' around the location: location '/Old Page Title.html' { return 301 $scheme://domain.com/new-url/; } Also see SO question Nginx rewrite that includes a blank spce.
  • 2,959
9 votes

nginx "ERR_TOO_MANY_REDIRECTS" after add ssl

In case someone is using CloudFlare and having the same issue. This fixed it: https://stackoverflow.com/a/60789055/3858492 In my case it was Cloudflare. I had to change to Full SSL encryption
  • 103
9 votes
Accepted

Nginx simple redirect of products from old to new category

Answering your questions in order... This rewrite ^/old-category/(.*) /new-category/$1; and this rewrite ^/old-category/(.*)$ /new-category/$1; as written are equivalent. The .* rule matches 0 or ...
9 votes
Accepted

wp-admin redirect loop when behind apache reverse proxy

The problem here is that your Internet-facing web server is using https, but the communication between that server and Apache2 is http. Then, Wordpress sees that the incoming connection is coming in ...
8 votes

Difference between "Redirect permanent" vs. mod_rewrite RewriteRule

Is one better then the other? Apache now recommends the use of Redirect from mod_alias instead of using RewriteRule from mod_rewrite. See https://httpd.apache.org/docs/current/rewrite/avoid.html#...
8 votes
Accepted

NGINX redirects to HTTP after port_in_redirect: off

By default, nginx issues an absolute URL in the 3xx response, which includes the scheme used to connect to the server. Your server at port 8080 is connected to over http, so that is the scheme that ...
8 votes
Accepted

Apache2 Virtual Host auto redirects to https

This problem occur with latest versions of chrome. This (.dev) domain is not available since 2017. Check this link below https://ma.ttias.be/chrome-force-dev-domains-https-via-preloaded-hsts/
  • 96
8 votes
Accepted

.htaccess Redirect 301 with trailing slash adds trailing slash to destination

But that redirects to example.php/ That is caused by the first (original) rule. Note that the earlier (erroneous) 301 will likely have been cached by the browser. Test with 302 (temporary) redirects ...
  • 12.1k
7 votes

How do I redirect www to non-www in Route53?

I was able to get this set up by leveraging an additional S3 bucket. I want my website to be accessible at the non-www example.com. In my case, example.com is set up with a route 53 hosted zone, a s3 ...
  • 171

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