I Recently migrated a website from PHP to rails. NEwt to the website they was a wordpress that is staying. the urls were as follow :
www.thedomain.com / #former PHP now rails
www.thedomain.com/blog/ #the wordpress.
now that the website is in Rails, i cannot just put a php wordpress in the blog folder.
I tried to go to a blog.thedomain.com solution using thoses route (actual domain names i use in dev as i am trying to make it work) :
namespace :blog do
match'', to: redirect {|params,request| "http://blog.fakefake1111/#{params[:path]}#{request.path}"}, via: :all
match '*path', to: redirect {|params,request| "http://blog.fakefake2222/#{params[:path]}"}, via: :all
end
It doesnt quite work, as the params are ignored and the first one add /blog/ at the end of the URL.
How can i make it work?
I will use the alias capability of apache to do it. I do not really need to use rails for that.
Related
I am trying to set the base address www.myplace.com/admin to be directed to www.myplace.com/admin/adminhub within the namespace coding below. I have tried every combination I can think of, but to no avail. I was trying to follow the same code used for the / of the app.
namespace :admin do
...
get "adminhub"
get 'admin', to: 'adminhub'
end
Sounds like you want to redirect the browser to the new URL. You can do this with the redirect helper in the routes.
get '/admin', to: redirect('/admin/adminhub')
This allows you to redirect from one path to another. See the Redirection section in the Rails Routing Guide for more details.
I have a website built in Ruby on Rails and a blog built in WordPress. The url for the main site will be example.com and the url for the blog is blog.example.com. Because of the way search engines index sites and the preference for a directory blog as opposed to a subdomain blog, I want to implement a permanent redirect so that example.com/blog/anything will redirect to blog.example.com/anything regardless of how many slashes or parameters the url contains. So even example.com/blog/a/b/c/d/e?google=true should redirect to blog.example.com/a/b/c/d/e?google=true
So far the following works if there is only one directory after blog:
get '/blog/:what', to: redirect('http://blog.codeundercover.com/%{what}')
I, however, need this to work regardless of what text comes after /blog. How do I do this?
Your route is not using a wildcard route. Instead, it's what the Rails Routing Guide refers to as a Static Segment
You'll want to use Wildcard Globbing instead:
get '/blog/*what', to: redirect('http://blog.codeundercover.com/%{what}'), constraints: { what: /.*/ }
get "/blog(/*what)", to: redirect("http://blog.codeundercover.com/%{what}")
I feel like this should not be all that difficult, but I cannot find any solutions that seem to work with Rails4
My setup
I have a proxy server (Kong) that directs to various services behind it based on path.
myapp.com/app1/ is redirected to http://app1_address:PORT/ (notice /app1 is stripped)
same for myapp.com/app2
app2 is a Rails 4 application and it works just fine when browsing to specific, but its relative routing is completely off. For example, link_to or url_for links to controllers or actions all redirect to the wrong links.
For example, I have a logout link that has a path of /logout on app2, but redirecting the user to /logout is incorrect. They need to be routed to /app2/logout. How can I configure the Rails app to add a prefix to all routes?
I have tried:
config.action_controller.relative_url_root = '/app2'
As well as this:
config.relative_url_root = '/app2'
And this in config.ru
map <MyAppName>::Application.config.relative_url_root || "/" do
run Rails.application
end
Any ideas for how to make this work?
You should use a scope in your routes:
Rails.application.routes.draw do
scope ENV["PROXY_PATH"] do
# your routes..
end
end
This way you'll have to set the ENV variable:
$ export PROXY_PATH=app2
$ bin/rails s
I've got a site with an api subdomain. On the same domain where the site is located, I've also got a dev subdomain with, you guessed it, a development version of the site.
My issue is that this dev version of the site also has an api subdomain (ie: api.dev.example.com. The routes work without issue using a regex to match the last segment of the subdomain against api (/api(?:\..*)?/), but the *_url helpers do not generate what I would like. Instead of spitting out http://api.dev.example.com/somepath, they spit out http://dev.example.com/somepath.
I'm looking for a solution that doesn't require special handling of the dev site vs the prod site. Subdomain sniffing based on requests so some such nonsense does not appeal to me.
Relevant routes.rb content:
constraints subdomain: /api(?:\..*)?/, format: 'json', protocol: 'http://' do
get '/' => 'example#index'
post '/create', to: 'example#create', as: :api_create_example
end
You can pass the subdomain to the url helper:
fear_and_loathing_in_las_vegas_url(subdomain: 'api.dev')
This will generate http://api.dev.example.com/fear_and_loathing_in_las_vegas
I set the blog as the root already. Then followed the tutorial at http://refinerycms.com/guides/page-titles-and-urls which says that to change the default slugs from Refinery, I needed to modify config/initializers/refinery/pages.rb to have config.use_custom_slugs = true . That part is done.
My blog is going to go on a subdomain similar to blog.example.com so hence it looks bad if I have blog.example.com/blog
So I already made sure to redirect the "home" to www.example.com so now I need to know how to remove the /blog from the url. So that click on "Blog" takes you to blog.example.com
In the Advanced Options, I tried setting the custom slug to "/" but that did not work as intended.
You need to change your routes.rb file to redirect to the blog index page. Make sure you put it before mounting the Refinery Core Engine.
Yourapp::Application.routes.draw do
root :to => 'refinery/blog/posts#index'
# This line mounts Refinery's routes at the root of your application.
# This means, any requests to the root URL of your application will go to Refinery::PagesController#home.
# If you would like to change where this extension is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Refinery relies on it being the default of "refinery"
mount Refinery::Core::Engine, :at => '/'
...
The Refinery Blog engine initializer has a "page_url" option you can change.
Uncomment the following line in config/initializers/refinery/blog.rb :
# config.page_url = "/blog"
And change it to
config.page_url = "/"
Not sure if this will work with a custom subdomain, but this is how to replace the default '/blog' route
I'm not really familiar with the innards of Refinery, but try putting this at the top of your routes.rb file:
get '/', to: redirect('/blog')
That should allow you to use the domain you want, though I believe it will redirect to the /blog before rendering.