I have made a kind of CMS using CodeIgniter. It loads the page content from Database depending on the slug text passed in the URL parameter like e.g. about, services, contact.
In the controller code, I have remapped the index method to take the slug as parameter to it as default index methods don’t allow parameters.
Check the code of my page controller on the link below :
The way this works is, I have set page controller to load as default. So every time I open my site like this
it loads the controller like this
If we pass the slug to it, it loads the page content of that slug from database, like this
http://www.mysite.com/page/about
http://www.mysite.com/page/portfolio
If we don’t pass the slug, it loads the home page.
Now what I want to do is, I don’t want this ‘page’ text to appear in URL. So pages should open like this
http://www.mysite.com/portfolio
I guess this will be possible through URL rewriting.
I have already done URL rewriting for removing index.php from URL which is normally done for all Codeigniter websites. Below is the code of my .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|uploads|fckeditor|assets|robots\.txt)
RewriteRule ^(.*)$ /jobsite/index.php/$1 [L]
Now the question is, how can I make the URL work like this
http://www.mysite.com/portfolio
Thanks in Advance.
Just add this to your config/routes.php file:
Then in *your_controller*, you can access the URI segment with:
Once you have the URI segment, you can query the DB for it and send the data off to your view. If the URI segment is empty, load the home page.