I am developing a website using Codeigniter.
i want to redirect a URL to its SEO Friendly version. for eg.
I have URL
A. http://www.example.com/post/[post-id]/
I want this URL to redirct to SEO Friendly version of itself
B. http://www.example.com/post/[post-id]/[post-title]
Just like stackoverflow is using and like redirecting A URL to B URL.
http://stackoverflow.com/questions/[question-id]/[question-title]
I was using 302 redirection in the Codeigniter until i read somewhere that if you are using 302 redirection.
then google might treat you as a Spammer but then again when i saw Stackoverflow URL Pattern then i think its much better to have B version of URL.
So my Questions are:
1. Which redirection stackoverflow is using?
2. Is it better to Store the Slug for [post-title] in database or manually calculate it with url_title() function.
create a private function in the posts controller for SEO friendly URLs for posts.
You should have a post_title member variable set before redirection. Where ever you are calling a redirect() function, replace it with your private function _redirect() and you are good to go.
by default its 302 redirect. To do a 301 redirect just add parameter to the redirect() function. e.g
Note: In order for this function to work it must be used before anything is outputted to the browser since it utilizes server headers.