Welcome Guest, Not a member yet? Register   Sign In
My URLS are partially faked, how can i redirect properly?
#1

[eluser]vtx220[/eluser]
Hello! I am really enjoying codeigniter and have gotten really far with it but there's an obstacle in the way. You see, my urls are partially faked so you can write anything you want at the end of them and it'll go to that page. Here's an example:

localhost.com/information/articles/3/article-name

is the same as

localhost.com/information/articles/3/fake-nake

also the same as

localhost.com/information/articles/3/

You may notice the pattern here that /3/ is the article number id and what comes after is the article's SEO url.

This becomes a problem when search engines start to index duplicate pages (bad for seo and risky to get blacklisted), and it is also bad for pranksters that want to do something like

localhost.com/information/articles/3/localhost-hates-monty-python

even though that's not true. So what can be done to fix this? Thank you so much in advance!
#2

[eluser]Twisted1919[/eluser]
have a "url" field in the database, generated with url_title() based on the article title.
when retrieving the article, compare the id and also the url, if they match, show the article, if they don't, redirect();

Also, a better SEO approach is a article url like:
localhost.com/information/articles/3-article-name
and do a explode() on the 3rd uri segment to retrieve the article_id and the url, like:
Code:
$uri=$this->uri->segment(3);
list($id, $url)=explode('-',$uri,2);
Of course, do additional checks for the obtained variables.
#3

[eluser]vtx220[/eluser]
Brilliant ideas! I will likely adopt the second idea for the next section considering that hte other ones are well indexed. I'll look into comparing the url to what it should be. The database has two urls, short which is what you get at the end, and full which is the url as a whole. The rest like category id, article id and so on are also there but with that tip I'm sure to get this working tomorrow ^^

Thank you!
#4

[eluser]Stoney[/eluser]
I had the same problem as you, duplicated URLs, because the client changed some product names a few times... so I had to query and verify the product name with the product ID.

Don't forget to do a 404 or redirect the fake ULR-s, to allow google to remove your duplicate pages.
#5

[eluser]Nisha S.[/eluser]
It is better to do a 301(permanent) redirect, so that search engine will re-index the page with same page rank, and will update the index.




Theme © iAndrew 2016 - Forum software by © MyBB