In this entry I am going to show how to, in a very search engine friendly way, update a URL for a particular page in a rails website. The rails routing system provides named routes, which are a very nice way to change the URL for a particular page and have all of your links update without having to change code in a bunch of different places. That is a great start on moving a page, but it doesn't take care of any links from outside of your site that might be pointing at the old URL. The best way to handle that is to make it so that the old URL redirects to the new URL, your end users won't notice a difference but the search engines bots will take note and update their indexes.
First off if you are not familiar with routing and named routes in rails you might want to read up on it. The rails API docs have some pretty good material on routes located at http://api.rubyonrails.org/classes/ActionController/Routing.htm
Lets pretend we are moving "http://example.com/users/signup" to "http://example.com/signup". Our original named route might look something like this:
map.signup '/users/signup', :controller => 'users', :action => 'signup'
And the code for a link that pointed to it would look something like this:
<%= link_to 'Signup', signup_url %>
To change our URL we would simply change the named route to look like this:
map.signup '/signup', :controller => 'users', :action => 'signup'
All of the links that used the named route would automatically change to link to the new URL but the old URL would stop working. To change that we could add the following to the routes file
map.signup_old '/users/signup', :controller => 'users', :action => 'signup', :old_url => true
This would allow the old URL to work, but it would be best if we made it so that it redirected to the new URL so that search engines would switch over to the new URL faster. Notice that there is an additional parameter that is defined on the end of the second route, this makes it so that we can easily differentiate what URL a visitor arrived on the page with.
Now all we have to do is make a method we can use in a before filter that redirects the user to the same action, the redirect will automatically use the first route we defined (as long as we leave them in that order in the routes file). In the users controller we would add the following code:
The lines in the route file would look like this:
before_filter :redirect_to_new_url
def redirect_to_new_url
if params[:old_url] == true
headers["Status"] = "301 Moved Permanently"
redirect_to({:action => action_name})
end
end
map.signup '/signup', :controller => 'users', :action => 'signup'
map.signup_old '/users/signup', :controller => 'users', :action => 'signup', :old_url => true
Once you have this in place you only have to add a new route to move a URL in a search engine friendly way, and when you decide that all the external links and search engines are updated all you have to do is get rid of the route that points to the old URL.
47 comments:
Memphis SEO training classes and seminars in Memphis, Tennessee from local training companies.
SEO Course in Chennai
Thanks for sharing this information. SEO is one of the digital marketing techniques which is used to increase website traffic and organic search results. If anyone wants to get SEO Training in Chennai visit FITA Academy located at Chennai. Rated as No.1 SEO Training institute in Chennai.
SEO Training in Chennai
Thanks for sharing this informative blog. I have read your blog and I gathered some valuable information from this blog. Keep posting. Recently I did Digital Marketing Courses in Chennai at a leading digital marketing company. It's really useful for me to make a bright career.
Thanks for very informative blog excellent information about SEO Training. I am planning to do SEO Training in Chennai. Please suggest me for best institute for SEO Training Institute in Chennai. I heard IICT Chromepet is best institute for SAP Training in Chennai what about SEO Training.
EMTV commenced broadcasting within the National Capital District of Papua New Guinea in July 1987.A transmission Centre was opened in Lae in April 1988 with Mt Hagen, Goroka, Arawa and Rabaul following in rapid succession. A milestone was reached in June 1989 when EMTV commenced being received live in Lae, Mt Hagen and Goroka.Twenty years later EMTV is now received in real time via satellite in 38 centres throughout Papua New Guinea.
PNG Entertainment News
Your website is beautifully decorated and easily navigated. I have enjoyed visiting this site today and hope to visit many more times in the future. If any one want to get more about Memphis local SEO service you may visit Memphis SEO .
SAP is one of the customer relationship management software and it support all end to end customer related process. To know more details about SAP modules please refer the following site.
Regards..
SAP Training Chennai
Thanks for sharing this niche useful informative post to our knowledge, Actually SAP is ERP software that can be used in many companies for their day to day business activities it has great scope in future.
Regards,
SAP training in chennai|SAP Course in Chennai
We enjoy your feedback. As opposed to problems, Personally i think a person sounded sensible. A nice career, in which such as every other, Seo Baclinks Blog Commenting Service And Seo Services..
Hi Admin,
Thanks for taking time to discussing about SAP, i was interesting to read from the beginning, keep your updates regularly...
Regards,
SAP MM Training In Chennai|SAP HANA Training in Chennai|sap training in Chennai
Jharkhand Labour Department Recruitment 2016
Good post. This is a very clear, informative and helpful post.......
Thanks for sharing this information. Please visit Bangladeshi Americans classified .
Really like it so much thanks for sharing amazing info..:) ecommerce web design company
Nice blog. happy to visit your blog. Thanks for sharing.
Digital Marketing Services in Chennai
Good post. Thanks for sharing such a informative post.
PPC training in chennai
This post has actually made me your fans and I have added your site to my favorites.SAP Simple Finance Training
Great article! Glad to find your blog. keep sharing.
digital marketing training in chennai
That was really great information on this blog , very interesting to read them ,
Thanks got to know more
Thanks for share
learn digital marketing and seo from our experts digital marketing training in bangalore | seo training in bangalore join to know more on it
Thanks for sharing such an informative post. Keep update more.
Digital Marketing Training In Chennai
Your blog is really useful for me. Thanks for sharing this informative blog.
The most advanced digital marketing training in Chennai for working professionals, business owners and job seekers - SKARtec Digital Marketing Academy
I have read your blog its very attractive and impressive. I like it your blog.
Google Search Engine Optimization Services Guaranteed SEO Company in India
SEO Company in India SEO Services in India
This post is very informative for everybody. I would like to appreciate your work for good
accuracy and got informative knowledge from here. Nice effort, very informative, this will
help me to complete my task. Thanks for share it keep it up.
Oracle Fusion HCM Training
Thanks for sharing the useful information and good points were stated in this article which is very informative and for the further information visit our site
Oracle Fusion Financials Training
Hi,
Thanks for taking time to discussing about SAP, i was interesting to read from the beginning, keep your updates regularly.people who interested to learn oracle and its suite just visit oue site for more info. Oracle EBS training
Thank you.
CALFRE handles oracle fusion financials online training and its modules maintaining classroom based training with the self-paced videos. An expert having ten plus years of self-experience handles the training period through online and explains each and every point perfectly. We recently launched our institute in the USA and getting
the best reputation over there.
Oracle fusion Financials Training in hyderabad
Oracle Fusion Financials online Training in hyderabad
RRB jobs
railway jobs
I like the post format as you create user engagement in the complete article. It seems round up of all published posts. Thanks for gauging the informative posts.
cara menggugurkan kandungan
Thank you for such sharing such great information with us.
Online Marketing Services
Top SEO Company in Bangalore
seo plans india
https://stitchclothes.com here we stitch clothes as per your design and selection
https://stitchclothes.com here we stitch clothes as per your design and selection
Your blog is extremely valuable for me. A debt of gratitude is in order for sharing this instructive blog.
Read Beard Press
Thank you for sharing valuable information
Mobile app development company in chennai
Web design company in chennai
Web development company in chennai
Thanks for sharing the information, Salesforce experts a lot of openings in multi-level companies, for more information n
Salesforce Training
Salesforce Online Training in Bangalore
Salesforce Training online in India
Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
Digital marketing course in chennai
Very useful and informative.
SAP S/4 HANA Simple Finance Training in Hyderabad
just information we only provide information for those who need it cara menggugurkan hamil
A. cara agar cepat hamil setelah selesai haid
B. cara agar cepat hamil
C. cara alami untuk segera mendapat kehamilan
D. makanan dan minuman agar cepat hamil
E. masa subur biar cepat hamil
F. panduan agar cepat hamil
We repair and service all models of Honor Service in Chennai, We rely on customer satisfaction. We can service all problems faced by Honor customers in Chennai.
Honor Service Center in Chennai | Honor Service Centre | Honor Service Center | Huawei Service Center in Chennai | Honor Service Center in velachery | Honor Service Chennai
we repair and service all models of oneplus Service in Chennai, We rely on customer satisfaction. We can service all problems faced by oneplus customers in chennai.
Oneplus Service Center in Chennai | Oneplus Service Centre | Oneplus Service Center | Oneplus Service Center near me | Oneplus Service Center in velachery | Oneplus Service Chennai
tgjobsnews is India's best job websiteAll central Govt Jobs
awesomestock is best shopping zone ethic wear dresses and Tops for women
Looking For RRB ALP Merit List? Look no more. Here, we are, providing the all RRB Merit List, may it be Group D, ALP, and RPF right, at one place at railwayresult.in. So, keep yourself updated with RRB Merit List.
I am really admired for the great info is visible in this blog that to lot of benefits for visiting the nice info in this website. Thanks a lot for using the nice info is visible in this blog.
Java training in chennai | Data Science Training in Chennai | DevOps Training in Chennai
Leading Mobile Service Centre in Chennai, We repair all models of smart phones like Samsung, Apple, Motorola, Lenovo, Redmi, Honor, Oneplus, Oppo, Coolpad, Htc and many other models.
Mobile Service Center in Chennai | Mobile Service Centre | Mobile Service Center | Mobile Service Center near me | Mobile Service Center in velachery | Mobile Service Chennai
Great Article
Final Year Project Domains for CSE
Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
Really nice and Useful information shared. I am very happy to read this article.
ERP in India
Cloud ERP Companies in India
Web development company in chennai
Thank you so much for posting this. I really appreciate your work. Keep it up. Great work!
CEH Training In Hyderbad
Post a Comment