Welcome Guest, Not a member yet? Register   Sign In
mod_rewrite help
#1

[eluser]eeerlend[/eluser]
Hi!

I want to use mod_rewrite to get all my url's that look like this:

domain.com/products
domain.com/products/123
domain.com/about

... to do this:

PageController -> index('products')
PageController -> index('products', '123')
PageController -> index('about')

...but keep normal behaviour on urls like this:
domain.com/admin (this is my admin panel located at domain.com/admin/index.php, and will have its own .htaccess file)
domain.com/templates (this is my templates folder located at domain.com/templates/)
domain.com/images (this is my images folder, with uploads, so should not be rewritten...)

I hope someone can show me how the .htaccess file should look like, since I don't have knowledge about mod_rewrite... I've also searched the user guide, but couldn't find a specific solution...

Thanks for ANY help!
#2

[eluser]Nick_MyShuitings[/eluser]
You could tackle it via htaccess and mod_rewrite, which would be very server specific and important to keep in mind for migration.

You could also use the routes functionality built into CI: http://ellislab.com/codeigniter/user-gui...uting.html

That would be the method that I would use to achieve what you requested... the second rule would look like this>

$route['product/:num'] = "PageController/index/$1";
#3

[eluser]eeerlend[/eluser]
[quote author="Nick_MyShuitings" date="1284792236"]

$route['product/:num'] = "PageController/index/$1";[/quote]

Thanks, so if I want to make this happen in my own CMS, I need to generate the routes on the go? Since from the backend, I want to create new sites, then let the user choose an "url alias" for that site.

Lets say I create a site called "About us", and choose "about" as the alias, and save to the database... That means the $routes array can be generated from the database?
#4

[eluser]eeerlend[/eluser]
By the way... my CMS generate all the front-end sites through ONE SiteController, then should load the modules in different positions. Thats why I want all urls to point to the SiteController, to generate the templates...
#5

[eluser]Nick_MyShuitings[/eluser]
I've never done it, but I recall reading in the forum a few methods for picking up the routes from the database. Its basically an extension to the routes.php class that after loading the config file, grabs the records from the db... that would allow you to save the aliases.

Do a google or forum search for CodeIgniter Database Routes.




Theme © iAndrew 2016 - Forum software by © MyBB