0

My application was built with WordPress. After 4 years I migrated from WordPress to Ruby on Rails 4.2.4.

My google page score is very good and I would like to redirect my WordPress links to my new setup (Ruby on Rails). My Ruby on rails applications link structure is different then WordPress.

PS: I still on same domain

WP Link Structure: my-website.com/year/month/day/Post-Title

Ruby on Rails Link Structure: my-website.com/p/Post-Title

How can I permanently move old links to my new links and have SEO in mind.

I am basically doing this for SEO

Rubioli
  • 685
  • 6
  • 34
  • http://stackoverflow.com/questions/15872233/ruby-on-rails-301-redirection – Eyeslandic Feb 21 '17 at 10:39
  • @Iceman Yeah this would work if the links were not on Wordpress. All the links are outside of the application/controller and its not just one redirect, its about 2000 redirects – Rubioli Feb 21 '17 at 10:45
  • Hey not used WP in a while, but you should check this plugin: https://wordpress.org/plugins/safe-redirect-manager/ – oreoluwa Feb 21 '17 at 10:53
  • Also checkout this post: http://madlemmings.com/2015/08/10/how-redirect-wordpress-page-plugins/ – oreoluwa Feb 21 '17 at 10:53
  • Thanks @oreoluwa These would work if my Wordpress application wouldn't be gone when migrating process was done. – Rubioli Feb 21 '17 at 10:55
  • then i think the `.htaccess` option would be your best bet IMHO! Although it also has its own separate considerations! – oreoluwa Feb 21 '17 at 10:58
  • Thanks @oreoluwa Yeah I was also thinking about `.htaccess `. What considerations? – Rubioli Feb 21 '17 at 10:58

1 Answers1

1

To redirect from old links structure to another, while keeping only a part of the original URLs, you must capture this part and use it in the target URL

RewriteEngine on
RewriteRule ^.+?/.+?/.+?/(.+)$ /p/$1 [R,L]

The first three .+? match year, month and day. The final (.+) captures the title, so it can be reused in the target URL /p/$1.

When everything works as it should, you may replace R with R=301 (permanent redirect). Never test with R=301.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • Thanks @Olaf. I use `Ruby on Rails 4.2.4` and `phusion passenger`. Can I add it to a `. htaccess` and if you are familiar with it, where to add the `.htaccess`. – Rubioli Feb 21 '17 at 11:10
  • If there are already some RewriteRules, you may insert this rule below `RewriteEngine on` and before any other rules. If this doesn't work for some reason, edit your question and show the current .htaccess file. – Olaf Dietsche Feb 21 '17 at 11:13
  • Thanks @Olaf. Currently I dont have `.htaccess`. One question in your answer you wrote: **To redirect from one site to another**. I don't redirect from one domain to another domain, I want to redirect **my old Wordpress urls** to my **new Ruby on rails url** In same domain. Does your solution still work? – Rubioli Feb 21 '17 at 11:17
  • Yes it does, just create the .htacces files with the given updated directives. – Olaf Dietsche Feb 21 '17 at 11:20
  • Thanks for your help @Olaf :) – Rubioli Feb 21 '17 at 13:35