We have a site at www.example.com but needs to move it to subdomain1.example.com, while maintaining the SEO links. We are planning to use Google's Change of Address but it requires 301 redirects.
We plan to release another site at the www.example.com address.
Is there a way to changes the routes.rb of www.example.com so that certain routes gets redirected to subdomain1 and others don't?
I am not sure exactly what you mean by redirect but here are some options:
You can redirect a route to another route in your rails app using:
get '/some_route', to: redirect('/other_route')
Or if the subdomain is a seperate app / service you can redirect in a controller using:
redirect_to "http://www.rubyonrails.org"
Related
I got my web platform built on ruby on rails at https://example.com
My landing and about pages are hosted in a Wordpress in other host at https://examplecms.com.
What i would like to achieve is to make users to visit https://example.com get masked https://examplecms.com except when they are logged in as my platform's dashboard is routed in the root path /.
What i am trying to avoid is the user to see in the URL https://examplecms.com.
I've tried so far a couple of tricks:
In my home/index action controller i've redirected to https://examplecms.com if the user is not signed in. But this fails as it still shows the CMS url in the user's browser.
Using an Iframe in the render of the home/index view pointing to the CMS site. It works because it stills present my site URL correctly but this seems kind of fishy also deep linking and navigating does not seem to work correctly.
I have been thinking into doing at proxy server level, using .htaccess or even using DNS strategies but i can't come up for a solution to these strategies to detect when the user is signed in or not?
Any ideas?
Thanks
Update:
Stack:
Ubuntu
Ruby on Rails
Nginx + passenger
Amazon Ec2 + Cloudflare DNS
You can use http://nginx.org/r/proxy_pass to silently redirect the user to a different page, without changing the URL that's shown to the user within the Location field of the browser.
To check whether the user is logged in, you can install an error handler via http://nginx.org/r/error_page to redirect the user only if your normal page returns an error (e.g., if the normal proxy_pass results in a 403 Forbidden response, then redirect the user's request to the alternative proxy_pass upstream as per the error handler).
What you're looking for is route scopes. I'm using Devise for authentication, which provides helpers for doing what you want, but I have no doubt you can adjust for your needs. When a user hits any page on the site, they are automatically redirected to the login. If they are logged in, they are redirected to the homepage/URL they typed in.
authenticated :user do
root to: 'titles#index'
end
devise_scope :user do
root to: 'devise/sessions#new'
end
Create a subdomain
For your WordPress hosted web content, you could create a very simple subdomain on your hosting provider like so
blog.example.com that is alias to examplecms.com
Use Device Gem for Authentication
You can use the device gem to authenticate the user and route the user to the subdomain. When the user hits the /root_path.
I have a requirement to redirect web request to another url in rails.
Lets take my current app is xyz.com. If I hit the xyz.com/mno/dashboard, it has to redirect to abc.com/dashboard.
Reality we don't have mno controller in xyz.com.
when it hits routes it needs to send the request to some controller(just consider like redirect controller)
In that redirection controller I want to handle my redirections to abc.com.
You can just handle this in your routes.rb config:
get '/mno/dashboard', to: redirect('http://example.com/dashboard')
(Note - replace example.com with abc.com. StackOverflow wont allow any other domain if prefixed with http(s)://)
I have a rails app with a page at http://mydomain.com/hello.
I would also like to have it mirrored at http://a.usersdomain.com, so that this URL is showing the same app, database, etc.
What I am imagining would be similar to how Tumblr allows you to host a blog at title.tumblr.com and usersdomain.com. Is this possible with a rails app?
You can pretty easily allow users to set up a subdomain on your domain. Just set up a wildcard subdomain with your DNS provider and you can have the rails app do the rest no problem.
So anything.myurl.com will go to your rails app. You can then have a method to get the subdomain and identify the user/site or whatever.
The users having their own domain redirect to the subdomain given can be done as Jason has mentioned in his answer.
You can use a A entry on your DNS management center for the domain. You would point subdomain of a to the IP address of the server that is hosting your rails app. If you do not have a static IP address (like Heroku by default) you can use a CNAME entry and point he subdomain on a to the item listed in the Domains area of the Heroku settings or directly to the current URL like tumblr would. For example on Heroku:
subdomain: a => myapp.herokuapp.com
or tumblr/other hosted url
subdomain a on your domain => title.tumblr.com
or your example:
subdomain a on usersdomain.com => mydomain.com
Hope this helps!
We have an application which uses five subdomains. One of those subdomains is changing.
I would like to be able to redirect everyone hitting the old domain to be redirected to the new one, and ideally use the Rails router so that I leave the processing there using Rack.
Is there a way of redirecting all traffic to one domain, to be redirected to another.
e.g all traffic to foo.app.com get's redirected to bar.foo.com, whilst maintaining the full path & query string.
As I am hosting with Heroku I have no .htaccess.
Refraction may be able to help with that.
I looked at subdomain-fu and it looks pretty easy to route all non-www and non-'' subdomain requests to a single controller.
But I also, need to send all external domains that are CNAME'd to my domain to the same controller. I have done a lot of searching and I can't find anything.
Summarized, if it is a subdomain on my domain it goes to Catchall controller, if it is any other domain than my domain, it goes to the same Catchall controller.
I am going nuts on this, any help would be appreciated.
You should check out the request_routing plugin. It allows you to easily route request by: subdomain, domain, method, port, remote_ip, content_type, protocol, etc.