views:

18

answers:

2

Hi

I have updated my website to now use the codeigniter framework my new urls are like the following example.com/index.php/home/page/page-title

The old urls are example.com/index.php?option=com_content&view=article&id=249

Ideally I want to do a redirect for all links formatted in the old way to the new links but there are a lot of pages on the website and the titles/id do not match.

I do not want to write an individual rule for every page. eg

Redirect 301 /oldpage.html http://www.example.com/newpage.html

I do not mind having all the wrongly formated urls be redirected to the home page/404 page if this easier.

I can see this requires a more complicated rule that uses regex something I have never been very good at.

Any help appreciated

Thanks

A: 

The server doesn't know which ID may match a given title. You will have to handle these cases in CodeIgniter. Build a table with all old IDs and new URIs. Write a script that handles these requests and does the redirect.

Example (I haven't touched CI recently):

.htaccess

# parameter 'id' followed by a '=' followed by a number
RewriteCond %{QUERY_STRING} id=(\d+)
RewriteRule ^ /redirector/url/%1? [L,R=301]

CodeIgniter

Redirector could be a CI class, that looks into url, validates it as a positive integer, searches the database for a matching new URI and sends a Location header.

toscho
A: 

Try the RewriteMap directive. See http://httpd.apache.org/docs/2.0/misc/rewriteguide.html for details.

J-16 SDiZ