Welcome Guest, Not a member yet? Register   Sign In
URL rewriting rules
#1

[eluser]JohnDoerther[/eluser]
Hey everyone!

My second week developing using CodeIgniter - I am loving it so much I am actually porting some older websites to MVC!

For one of the websites I am porting, links look like this:

Code:
http://127.0.0.1/index.php?/home

On all the pages, for example the frontpage under
Code:
/home/index
, there are a bunch of static php links, for example about.php.

Want I would like to do is port the old website to CodeIgniter, but without changing the URLs - in other words, when visting
Code:
http://127.0.0.1/about.php
, I would like to define specific redirection rules for every page, for example mapping
Code:
http://127.0.0.1/about.php
to
Code:
http://127.0.0.1/index.php?/home/about
.

Is this possible using CodeIgniter? Changing the URLs is not an option, since this would break a lot of links...
A dynamic way of doing this would be perfect (something that says "map all traffic in 127.0.0.1/x.php to 127.0.0.1/index.php?/x for example" but if I have to manually define the rule for every page, that is fine too...

Best wishes and thanks in advance
#2

[eluser]pickupman[/eluser]
You will need to use .htaccess and mod_rewrite to remap the url's to your CI site.
Code:
RewriteEngine on
RewriteRule ^about\.php$ /index.php?/home/about [L] //Could change to [L,302] for a redirect
#3

[eluser]loosetops[/eluser]
Use the routes file. config/routes.php

Code:
$route['about\.php'] = 'home/about';

You should first get rid of the index.php in the URL so that the route definitions are less cluttered.

To get rid of it

.htaccess
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

and in the config.php
Code:
$config['index_page'] = "";




Theme © iAndrew 2016 - Forum software by © MyBB