Hi all -
My boss is asking me if we can have dashes instead of underscores in the
URL for SEO reasons. Apparently google prefers “foo-bar” to “foo_bar”.
The former will be found when searching for just “foo”, but not the
latter.
So, I’m wondering if there is a way without changing any of my code
if I can tell rails to use dashes instead of underscores?
Any ideas?
Philip H. wrote:
Hi all -
My boss is asking me if we can have dashes instead of underscores in the
URL for SEO reasons. Apparently google prefers “foo-bar” to “foo_bar”.
The former will be found when searching for just “foo”, but not the
latter.
So, I’m wondering if there is a way without changing any of my code
if I can tell rails to use dashes instead of underscores?
Any ideas?
Im a n00b but, maybe look into mapping it like this:
map.connect ‘foo-bar’, :controller => “foo_bar”
edit
Im a n00b but, maybe look into mapping it like this:
map.connect ‘/foo-bar’, :controller => “foo_bar”
edit
Im a n00b but, maybe look into mapping it like this:
map.connect ‘/foo-bar/:action’, :controller => “foo_bar”
How would this affect say a link_to call in a view…
say
link_to “some place”, :controller => “does_this_need_underscores”,
:action
=> “act”
Would this then be mapped to the dash route?
I think so but rendering I would test
Text
so map should fix. As for rendering that needs to be ran by a test
Philip H. wrote:
Hi all -
My boss is asking me if we can have dashes instead of underscores in the
URL for SEO reasons. Apparently google prefers “foo-bar” to “foo_bar”.
The former will be found when searching for just “foo”, but not the
latter.
So, I’m wondering if there is a way without changing any of my code
if I can tell rails to use dashes instead of underscores?
Any ideas?
map.connect ‘foo-bar/:action/:id’,
:controller => ‘foo_bar’,
:action => nil,
:id => nil
url_for :controller => ‘foo_bar’
#=> /foo-bar
url_for :controller => ‘foo_bar’,
:action => ‘narf’
#=> /foo-bar/narf
url_for :controller => ‘foo_bar’,
:action => ‘show’,
:id => @foo.id
#=> /foo-bar/show/123
Setting the routing params to nil tell the router they are optional.