Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
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,277
25 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; ...
Tero Kilkanen's user avatar
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 ...
Hardeep Singh's user avatar
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, ...
John Pope's user avatar
  • 151
13 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
Yacine al's user avatar
  • 143
12 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 ...
Mahmoud Al-Qudsi's user avatar
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 ...
MrWhite's user avatar
  • 13.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.
AlexD's user avatar
  • 10.4k
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
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 %{...
Nadir's user avatar
  • 231
9 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 ...
Federico's user avatar
  • 191
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, ...
Jonny Mac's user avatar
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.
Paul's user avatar
  • 3,167
9 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 ...
Richard Smith's user avatar
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 ...
Daniele Santi's user avatar
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 ...
Tero Kilkanen's user avatar
8 votes

NGINX redirect everything except letsencrypt to https

Well, wasn't the HSTS in my case server { # ... location /.well-known/acme-challenge/ { # put your configuration here, if needed } location / { return 301 https://$...
ᴍᴇʜᴏᴠ's user avatar
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
8 votes
Accepted

Apache Conditional Redirect HTTP to HTTPS

But now my certificate seems to need HTTP. This is not quite correct. I am personally renewing over https. In order for that to work however, you need make sure to allow access to the challenge URI ...
cetteup's user avatar
  • 166
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/
Rayyan's user avatar
  • 96
8 votes
Accepted

nginx "ERR_TOO_MANY_REDIRECTS" after add ssl

That's because you're redirecting all connections to https, even https connections, which means you create a redirect loop. Change your config to server { listen 80 default_server; ...
Broco's user avatar
  • 2,029
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 ...
MrWhite's user avatar
  • 13.1k
7 votes

Convert and redirect URL in uppercase to lowercase using .htaccess

If you are on Apache 2.4 then in .htaccess you can use mod_rewrite with an Apache expression in a RewriteCond directive to make use of the tolower() function. (You no longer need access to the server ...
MrWhite's user avatar
  • 13.1k
7 votes

Amazon Cloudfront with S3 Redirect

If you have this issue, check first when you configure the s3 bucket origin for the cloudfront, the autocomplete returns the s3 REST endpoint domain.amazonaws.com which return this ListBucketResult ...
lapinkoira's user avatar
7 votes
Accepted

Redirect all subdomains to main domain inside vhost

Just add a block below the main block in your vhost configuration file. Just specify ServerAlias using the wildcard * for the subdomains. Finally, specify the redirect address using ...
openwonk's user avatar
  • 186
7 votes

NGINX redirect everything except letsencrypt to https

You can create a snippet to use in your config in /etc/nginx/snippets.d/letsencrypt location ~ /\.well-known/acme-challenge/ { allow all; default_type "text/plain"; root /usr/share/...
rubo77's user avatar
  • 2,519
6 votes

Nginx Redirect via Proxy, Rewrite and Preserve URL

You can use the following config to have a 100% seamless mapping between /some/path/ on the front-end and / on the backend. Note that this is the only answer so far that would also seamlessly take ...
cnst's user avatar
  • 14.3k
6 votes

Different Nginx redirects based on upstream proxy response

The exact solution to the question is to use the Lua capabilities of Nginx. On Ubuntu 16.04 you can install a version of Nginx supporting Lua with: $ apt install nginx-extra On other systems it ...
harm's user avatar
  • 201
6 votes
Accepted

apache redirect only root slash homepage

You need to use mod_rewrite: RewriteEngine On RewriteCond "%{QUERY_STRING}" "^$" RewriteRule "^/$" http://something-other.org/ [L,R=301,QSD] The QSD flag discards the query string. Enable ...
rda's user avatar
  • 1,987
6 votes
Accepted

Apache DirectorySlash redirects HTTPS requests back to HTTP

Since rewrite will kick in before DirectorySlash, here is what ended up with and it works: # Redirect to HTTPS before Apache mod_dir DirectorySlash redirect to HTTP RewriteCond %{HTTP:X-Forwarded-...
starchx's user avatar
  • 533

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