# Flaw in permalinking system

**URL:** <https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814>\
**Category:** Rails\
**Created:** [September 11, 2010, 8:29am UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814 "2010-09-11T08:29:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 11, 2010, 8:29am UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814/1 "2010-09-11T08:29:27Z")

</div>

Hi

Basically I have a permalink system setup using the to\_param method in  
the model file. Since I have a system in which categories has\_many  
tutorials, my URLs look a bit like this:

[site.com/CatID-Category-Perma/TutID-Tutorial-Perma](http://site.com/CatID-Category-Perma/TutID-Tutorial-Perma)

I have a system to redirect when the user puts in an ID to the proper  
permalink; like this:

@tutorial = Tutorial.find(params[:id])  
@category = Category.find(params[:category\_id])  
if isNumeric(params[:id]) || isNumeric(params[:category\_id])  
redirect\_to tutpmlnk\_path(:category\_id =\> @tutorial.category, :id =\>  
@tutorial)  
return false  
end

However there is still a massive problem in my permalink system; which  
is if the user types in a wrong permalink it still goes to the correct  
page (and counts as duplicate content). For example:  
The proper URL to an example page: [site.com/CatID-Category-Perm](http://site.com/CatID-Category-Perm)  
The wrong URL that works: [site.com/CatID-ANYTHING](http://site.com/CatID-ANYTHING)  
This also works if you put the tutorial ID followed by anything.

I need to try and find a way to redirect these wrong URLs to the right  
ones; I’ve spent hours and hours trying to figure out ways around it  
but none of them seem to work. Could someone PLEASE help me with this  
massive issue in my permalink system?

Please Help,

Thanks In Advance,

Joe

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 11, 2010, 10:56am UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814/2 "2010-09-11T10:56:55Z")

</div>

Just check if request.fullpath or request.path include  
tutpmlnk\_path(:category\_id =\> @tutorial.category, :id =\>  
@tutorial) string. If so render otherwise redirect to proper path.  
What do you think ? And btw ? Why is it so important ? Who visits the  
wrong links ?

Robert Pankowecki

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 11, 2010, 2:45pm UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814/3 "2010-09-11T14:45:44Z")

</div>

I don’t know what request.path or request.fullpath are, or how to  
check if they include my redirect thing (I’m a real RoR noob); but  
I’ll be looking around files for them.

As for why it’s so important; firstly I still need to perfect the  
permalink system (remove some more punctuation), and don’t want people  
linking wrongly (as the link they know would have been correct at the  
time); secondly if google see one link I’m pretty sure they are going  
to think it’s duplicate content. And thirdly I want to have a sound  
permalink system and overall site.

Please Help,

Thanks In Advance,

Joe

On 11 Sep, 09:54, “Robert Pankowecki (rupert)”

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 11, 2010, 2:48pm UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814/4 "2010-09-11T14:48:40Z")

</div>

I don’t know what request.path or request.fullpath are, or how to  
check if they include my redirect thing (I’m a real RoR noob); but  
I’ll be looking around files for them.

As for why it’s so important; firstly I still need to perfect the  
permalink system (remove some more punctuation), and don’t want people  
linking wrongly (as the link they know would have been correct at the  
time); secondly if google see one link I’m pretty sure they are going  
to think it’s duplicate content. And thirdly I want to have a sound  
permalink system and overall site.

Please Help,

Thanks In Advance,

Joe

On 11 Sep, 09:54, “Robert Pankowecki (rupert)”

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 11, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814/5 "2010-09-11T14:51:01Z")

</div>

I don’t know what request.path or request.fullpath are, or how to  
check if they include my redirect thing (I’m a real RoR noob); but  
I’ll be looking around files for them.

As for why it’s so important; firstly I still need to perfect the  
permalink system (remove some more punctuation), and don’t want people  
linking wrongly (as the link they know would have been correct at the  
time); secondly if google see one link I’m pretty sure they are going  
to think it’s duplicate content. And thirdly I want to have a sound  
permalink system and overall site.

Please Help,

Thanks In Advance,

Joe

On 11 Sep, 09:54, “Robert Pankowecki (rupert)”

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 11, 2010, 8:40pm UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814/6 "2010-09-11T20:40:28Z")

</div>

`request' is a method available in your controller. It returns ActionDispatch::Request instance. `fullpath and `path' are method that can be called on `request’ instance.

You might wanna try friendly\_id .

> **[Category: Rails Permalinks & Slugs - The Ruby Toolbox](https://www.ruby-toolbox.com/categories/rails_permalinks___slugs.html)**
>
> Explore and compare open source Ruby libraries

It has the feature that object can be found by their historical  
permalinks and redirected to the current one. Nice thing to have in  
case you manipulate your permalink system.

Robert Pankowecki

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 12, 2010, 8:23am UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814/7 "2010-09-12T08:23:56Z")

</div>

Looking through all of my controllers I can’t see anything about any  
requests…  
As for friendly URLs, I might look at it at some point; but for now is  
there anyway I could just make another if statement in the controllers  
to make it redirect if it has the wrong permalink? (Not only would  
this mean I could easily solve the problem, but that I would get a  
greater understanding of Ruby on Rails through it).

I’ve tried for hours and hours to try and find a solution but just  
can’t figure it out…

Please Help,

Thanks In Advance,

Joe

On 11 Sep, 19:39, “Robert Pankowecki (rupert)”

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 12, 2010, 11:41am UTC](https://www.ruby-forum.com/t/flaw-in-permalinking-system/194814/8 "2010-09-12T11:41:08Z")

</div>

@tutorial = Tutorial.find(params[:id])  
@category = Category.find(params[:category\_id])  
if isNumeric(params[:id]) || isNumeric(params[:category\_id])  
ok\_path = tutpmlnk\_path(:category\_id =\> @tutorial.category, :id =\>  
@tutorial)  
redirect\_to ok\_path unless request.fullpath.include?(ok\_path) #  
sth like that… Not best, bo ok for beginning.  
…  
end

`request' is a method defined in your controller superclass. Same thing as`params’.

Robert Pankowecki
