How can I redirect mydomain.com
and any subdomain *.mydomain.com
to www.adifferentdomain.com
using NGINX?
相关问题
- Stop .htaccess redirect with query string
- UrlEncodeUnicode and browser navigation errors
- How can I prevent my Shiny App from disconnecting
- Can't configure nginx as a proxy for tomcat wi
- How to set Nginx URI to fix empty URI in redirect
That should work via HTTPRewriteModule.
Example rewrite from www.example.com to example.com:
Why use the rewrite module if you can do
return
? Technically speaking,return
is part of the rewrite module as you can read here but this snippet is easier to read imho.You can also give it a 301 redirect.
If you would like to redirect requests for "domain1.com" to "domain2.com", you could create a server block that looks like this:
server_name supports suffix matches using .mydomain.com syntax:
or on any version 0.9.1 or higher:
http://wiki.nginx.org/HttpRewriteModule#return
and
http://wiki.nginx.org/Pitfalls#Taxing_Rewrites
Temporary redirect
Permanent redirect
In nginx configuration file for specific site: