Last active
July 8, 2020 09:16
-
-
Save khiet/35f9381fac71414268c004cd89549567 to your computer and use it in GitHub Desktop.
Rails 5 redirect root domain to www and vice versa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example.com => www.example.com | |
match '(*any)', to: redirect(subdomain: 'www'), via: :all, constraints: { subdomain: false } | |
# www.example.com => example.com | |
match '(*any)', to: redirect(subdomain: false), via: :all, constraints: {subdomain: 'www'} | |
# caveat | |
# subdomain is anything from 3rd level domain, so for example.co.uk domains the syntax will be the following: | |
# example.co.uk => www.example.co.uk | |
match '(*any)', to: redirect(subdomain: 'www.example'), via: :all, constraints: { subdomain: 'example' } | |
# www.example.co.uk => example.co.uk | |
match '(*any)', to: redirect(subdomain: 'example'), via: :all, constraints: { subdomain: 'www.example' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment