I implemented canonical url for homepage as follows: I added this line
<link rel='canonical' href='https://example.com/'>
I added this line on index.html.erb
in header
section. It is working fine.
Now I have dynamic routes generating line as follows:
<a href "<%= search_equipments_path(:category_id => category.id) %>">
I tried with following:
<a rel='canonical' href="<%= search_equipments_path(:category_id => category.slug) %>">
But didn't work.
We can set canonical tags in rails this way. This rails code will output canonical tags for full current url. Add this in layout in HTML head section.
<link rel="canonical" href="<%= url_for(:only_path => false) %>" />
You can also specify the default protocol to be use for this URL by using:
<link rel="canonical" href="<%= url_for(:only_path => false, :protocol => 'https') %>" />
For more options please refer this link
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With