Reputation: 156
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
Upvotes: 0
Views: 923
Reputation: 26910
Try the RewriteMap
directive. See http://httpd.apache.org/docs/2.0/misc/rewriteguide.html for details.
Upvotes: 0
Reputation: 63576
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):
# parameter 'id' followed by a '=' followed by a number
RewriteCond %{QUERY_STRING} id=(\d+)
RewriteRule ^ /redirector/url/%1? [L,R=301]
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.
Upvotes: 1