SEO for Rails site, now or later? - ruby-on-rails

My freelance web developer is developing a site on Ruby on Rails. Currently the URL structure is
http://abc.com/all?ID=category
Example:
http://abc.com/all?3=CatA
I requested him to structure the URL according to categories, such as
http://abc.com/CatA/3-page-title
but he refused cos it was too much work and cost involved as he is using the same model for Category A, Category B... I thought the URL structure that he is using is messy and not search engine friendly.
My question is, should I add cost to let him do a better structured URL I requested, or should I let the project finish, then do it in the next iteration?
I'm worried that if I do it in the next iteration, all the previous URLs structured in the old way will be purged and when sites that refer to it will show a 404 error. It's like I have to rebuild the site ranking all over again.
Any other solutions for me? Is that any way to redirect old URLs to new URLs automatically in Rails?

The way your developer is proposing to compose the URLs would be considered something of an anti-pattern is Rails. What you are looking for is close to what Rails does out-of-the-box when using RESTful resource routing, admittedly, I'm guessing as to how CatA and page-title are related to each other. A RESTful Rails route might look like this (using your example):
http://abc.com/categories/3-CatA/pages/10-page-tite
If he really is using Rails, and he knows what he's doing, then there should be no cost at all to converting to what you want. It just needs the correct routes defined and then a to_param override in your models to get the nice SEO friendly identifiers.

Related

Ruby On Rails Overlapping Routes

I'm rebuilding/redesigning a site in Rails that's currently in production using Magento. To ensure that I don't lower my seo rankings I am keeping my URI's the same. I am facing an optimization issue with this because the current site doesn't have subdirectories. With that said, the products are under the root directory of the site, the reviews are under the root directory of the site, and all the other content pages are under the root directory of the site.
for example a product might be at
www.example.com/some-product-name
and a review could be at
www.example.com/some-review-name
rails obviously uses routes and my first guess was to make a route that looks like this:
get '/:uri_identifier', to: 'pages#find_page'
This works fine, but with 50k products to query through and 5k reviews along with another 200 different content pages, this creates an optimization issue since this controller method becomes a catch all to figure out which page it should render based on
params[:uri_identifier]
The uri's don't have any kind of form either so filtering them with an if statement to avoid large amounts of queries isn't really feasible. My idea was to create routes specific for the reviews and add them in routes.erb above the route
get '/:uri_identifier', to: 'pages#find_page'
but I'm still going to have to create close to 5k routes to pull this off. I did try this and it worked, but I'm not real sure what is the best way to approach this issue to ensure that I use the least amount of resources.
There are several patterns for solving this kind of problems in rails. One of which is slug constraint. Use this resources they help with the concept of using slugs and refactoring large rails routes
http://blog.arkency.com/2014/01/short-urls-for-every-route-in-your-rails-app/
http://code-worrier.com/blog/custom-slugs-in-rails/
Refactoring a large routes.rb file in rails 4

ASP.NET MVC and friendly URLs

I'm trying to learn a bit more about creating friendly URLs, particularly in relation to something like an e-commerce site. If you take a look at this site as an example: http://www.wiggle.co.uk/
It basically lets you refine your search based on the categories. So if I go to http://www.wiggle.co.uk/mens/road-time-trial-bikes/ it will list all men's road bikes, if I then go to http://www.wiggle.co.uk/road-time-trial-bikes/ it will list men's and women's bikes, and if I go to http://www.wiggle.co.uk/bianchi-sempre-105/ it will display a particular bike.
I'm not really sure what the routing would look like for something like this, as you could have many filters in the URL. I'm also not sure how how it's able to distinguish between what's a filter and what's a product.
I'd say you are fairly close but would break out the second and third as it would be a little ambiguous for the one Action to interpret the two parameters. I'd suggest the following:
http://www.wiggle.co.uk/road-time-trial-bikes/
http://www.wiggle.co.uk/bikes/bianchi-sempre-105/
Thus /bikes/ could be routed clearly to a different controller and action. You would need to create a specific rule for the root or you could add a specific controller, say bike-types, to the first url
http://www.wiggle.co.uk/bike-types/road-time-trial-bikes/
The specifics on routing are well documented but a good place to start might be with writing some tests to help you understand what works and give you more confidence with making changes to your routes. It is very easy to create clashing routes and tests help prevent this.
http://mvccontrib.codeplex.com/wikipage?title=TestHelper#Routes

How can I change the way links look and act in my Rails 3 application?

I have brands and products, and there is a nightly load that replaces them. A brand may end up with a new id, and a product will always end up with a new id. But I have customers that want static links to these dynamic ids.
I would like a link that now looks like:
.mysite.com/brands/17/products/168390
to look like:
.mysite.com/products/ABC123
where "ABC123" is an alphanumeric identifier not associated with the id. Think of it like a model number.
I don't need anyone to give me the answer, I am happy to do the work. But any pointers to where I can get started would help, as I apparently don't have the right terminology to do a successful Google search.
Thanks!
I would suggest watching the screencasts done by Ryan Bates at RailsCasts.
For your question on how to change the products URL away from id, the specific ones would be Model Name in URL or Semi-Static Pages (just the information on how the routing is accomplished). For your question on the shortening the nested URLS, what you want would be his cast on Nested Resources.
Those are the ones that have to do with your specific problems, however I would suggest watching all of them in order to learn more about the framework. One thing to note is that since those are fairly old, things may have changed some in Rails 3, however I imagine that once you get something to Google, you will be able to find how to do it in Rails 3 fairly easily.
Do it using rails routes. Something like:
match 'products/code/:product_code' => 'products#code'
There are lots of things you can do with routes - my suggestion would be to familiarize yourself with them.

CakePHP and Rails: slowly port old php functionality to new rails

I am a rails developer working on a cakephp site. The more work they send me, the more php code I write and thus the more dependence on php we introduce. What I want is to stop writing new features in php and start writing them in rails. Our resources are limited and the existing php site is huge so a full port from cake to rails is not possible.
Is there some way to write new features in a rails app while maintaining and allowing access to all the functionality of the old php (and vice-versa)?
It seems I would need a route aware app to traffic requests to either php or rails, but then we run into the issue of, for example, existing user functionality written in php not being available to the rails app and vice-versa.
What about something to translate ruby into php? That way I could start writing my model stuff in ruby/rails rather than php.
I feel like my question is muddled by the fact I do not know how to ask the questions I want to answer, so hopefully this is understood.
As always, thanks in advance!
One approach that you may find useful is to leverage the power of your web-server to properly re-write and delegate requests to two different systems. If you can design your new Rails application to use the same database records as the old one, with models mapping to the old tables directly, and ensuring that sessions established by one are valid in the other, you have a lot of latitude in how you go about doing this.
Apache has a very full-featured URL rewriting and proxying system that can be configured to direct "legacy" parts of your site to an existing set of PHP scripts while directing all other traffic to the new Rails application. You will need to be careful to ensure the design of both applications are nearly identical or it may seem strange to users.
Another approach that helps ensure a consistent appearance is to strip out a lot of the theme from your PHP application. By creating very bare-bones pages that only expose the required functionality on each page, Rails can fetch these by passing through any relevant session authentication information and re-frame them in the right layout.
This way you can preserve existing functionality and have it embedded inside your new application. You can use something as simple as open-uri or the curb gem to handle this HTTP-level delegation.
You would end up with controllers that look like this:
class PaymentController < ApplicationController
def index
#content = fetch_legacy_url('/payments/index.php'))
end
end
The fetch_legacy_url method would create an HTTP fetch request that includes the required headers, cookies, and so forth, and return the response body. Your view then ends up looking something like this:
<%= #content =>
From there you can shunt parts of the PHP layout over to the Rails app piece by piece. For instance, ripping out large chunks of static HTML and putting them in the Rails template would reduce the amount of actual PHP code you have to port.
It's a bit messy to maintain two applications in parallel, but as you point out the alternative is to keep accumulating technical debt and making the inevitable re-write that much more significant an undertaking.
The first step would be to experiment and see if you can create a Rails environment that uses your existing data, or at least the data relevant to the new functionality you intend to build out.

What makes an effective URL Mapping implementation and why?

I am looking at implementing URLMapping for a personal project. I am already aware that solutions exist so please do not answer suggesting I should use one.
What I want is to harvest the opinions of fellow developers and web users on URL mapping implementations. Specially I would like you to answer:
Which is your favourite implementation?
What do you like about your favourite implementation?
What do you not like about your favourite implementation?
How would you improve it?
I would like you to answer from two points of view:
As a developer
As a user
I would be grateful for any opinions on this matter, thanks!
I've only worked with django's URLConf mechanism. I think the way it relies on the urlpatterns variable is a bit flimsy, but I like its expressiveness in specifying patterns and dispatching to other url configurations. I think probably the best thing is to figure out your URL scheme first, and then try out a couple of solutions to see what matches best. If you're going hard-core REST using the full complement of GET/POST/PUT/DELETE, and checking the user agent's Accept headers, and all that, django will, by default, have you splitting your logic between URL config files and view files, so it might not be the cleanest solution.
However, since it's all Python, you might be able to do some more complex processing before you assign to urlpatterns.
Really, you want a system that does what you need. Your URL scheme is your API, so don't compromise on it based on the tools you use. Figure out your API, then find the tools that will let you do that and get out of your way.
Edit: Also do a google search for "URL scheme design." I found this without much effort: http://www.gaffneyware.com/urldesign.htm. Not comprehensive, but some good advice gotten from looking at what flickr does.
Well, I should have noticed the url-routing tag shouldn't I? :-) Sorry about that.
jcd's experience mimics mine - Django is what I use too.
I like the fact that the routes for an app reside within the app (in urls.py) and can just be included into any projects that might make use of that app. I am comfortable with regular expressions, so having the routes be specified in regex doesn't phase me (but I've seen other programmers scratch their heads at some more uncommon expressions).
Being able to reverse a route via some identifier (in Django's case by route's name) is a must. Hardcoding urls in templates or controllers (view in Django) is a big no-no. Django has a template tag that uses the reverse() method
The one thing I wish I could do is have the concept of default routes in django (like Rails does or even Pylons). In Django every route has to map to a view method, there is no concept of trying to call a certain view based on the URL itself. The benefit is that there are no surprises - your urls.py is the Table of Contents for your project or app. The disadvantage is that urls.py tend to be longer.

Resources