473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

CodeIgniter: Default controller

TheServant
1,168 Expert 1GB
Hi all,
I am trying to do something in CI which I cannot find any documentation for. I have set up my .htaccess so that if a file does not exist, and no controller/function is called it goes to the home page, but what I want is this:
Instead of http://mysite.com/controller/function/variable
I just use http://mysite.com/variable and it simply uses the default controller and index function.

The reason is, I am creating a CMS where pages will be retrieved like:
http://mysite.com/page/display/home
But I would much prefer:
http://mysite.com/home
http://mysite.com/contact
http://mysite.com/about

Anyone done this or know how to?
Sep 21 '09 #1
7 8282
Dormilich
8,658 Expert Mod 8TB
basicly something like this
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^([a-z])$ page/display/$1
you might add your personal constraints, though.
Sep 21 '09 #2
TheServant
1,168 Expert 1GB
I have been trying to do something like that, however my mod rewrite skills are a bit behind. I have this:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteRule ^(application) - [F,L]
  3. RewriteCond %{REQUEST_FILENAME} !-f
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. RewriteRule ^(.*)$ index.php/page/index/$0 [PT, L]
Just checks if the file/directory exists, if not, then it should redirect to mysite.com/index.php/page/index/page_requested but it doesn't and I get a 500 error. Any help?
Sep 21 '09 #3
Dormilich
8,658 Expert Mod 8TB
don’t know too much mod_rewrite myself…

a) check the syntax (manual)

b) check if you are allowed to use mod_rewrite. wrap the code in
Expand|Select|Wrap|Line Numbers
  1. <IfModule mod_rewrite.c>
  2. </IfModule>
c) use a RewriteBase

d) (has nothing to do with the error) check for a / in the variable string (i.e. use a different RegEx)
Sep 21 '09 #4
TheServant
1,168 Expert 1GB
Well I don't know how to do this. I have realized that my removal of 'index.php/' with the following in my htaccess is not working:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteRule ^(application|system) - [F,L]
  3. RewriteCond %{REQUEST_FILENAME} !-f
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. RewriteRule (.*) index.php/$0 [PT,L]
Yes I have already changed my config file so that $config['index_page'] = "";

Anyone solved a similar problem?
Sep 21 '09 #5
TheServant
1,168 Expert 1GB
SOLVED!!! I changed this in my config:
Expand|Select|Wrap|Line Numbers
  1. $config['uri_protocol']    = "AUTO";
~to~
Expand|Select|Wrap|Line Numbers
  1. $config['uri_protocol']    = "ORIG_PATH_INFO";
Don't know what it does, but it works!


------------------------------------------------------
Edit:
I have just changed it back to AUTO as I found it stuffs up the search engine friendly URL's, and found another solution. htaccess was changed to include a "?" like so:
Expand|Select|Wrap|Line Numbers
  1. RewriteRule (.*) index.php?/$0 [PT,L]
Sep 21 '09 #6
Markus
6,050 Expert 4TB
CI has this functionality built in: routing. In your config/routes.php file, try some thing like this:
Expand|Select|Wrap|Line Numbers
  1. $route['(a-z+)/?'] = "page/display/$1";
  2.  
Sep 21 '09 #7
TheServant
1,168 Expert 1GB
Ha! Nice work Markus, I was trying to get that to work before with no luck, but tried a little harder and voila!

I have another small problem though... Now none of my error pages work:
The page you requested, 403_shtml, could not be found. <-- This is my error display message.
I have realised that if I run everything through my other function, these pages won't work. Any ideas?
Sep 21 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Fritz Bosch | last post by:
We are in the process of refactoring our GUI-based test application for radio equipment and are rewriting a significant part in Python. The new architecture will substantially be based on the...
2
by: Stan | last post by:
I want to make two pages interact through a controller. 1. Page A has a grid and Add button. 2. When Add button is clicked Page B pops up. 3. User enters information and clicks Save 4....
1
by: Andy Fish | last post by:
Hi, I have been thinking about the design of a large ASP.NET app and I've read people have a lot of trouble implementing front controller, especially with postbacks, so I don't feel comfortable...
4
by: Griff | last post by:
Two questions really, the first one "conceptual" and the other more involved with design: 1 - There are two schools of thought where I work on the role of the "controller" task. The first is...
5
by: uspensky | last post by:
We are trying to setup a system to system failover cluster using two nodes (x346) which each have a single hba running to seperate controllers on the DS400. For full redundnancy, IBM recommends...
1
by: Gerry Vandermaesen | last post by:
Hi, I was looking into CodeIgniter, and encountered the following problem: In codeigniter, you could create a new controller like this: --- class People extends Controller { function...
0
by: surfivor | last post by:
I am doing some preliminary research as we are slated to do a project with wordpress. I looked at the wordpress code and realized why I like MVC so much (Rails) because the code mixed in with the...
1
by: Robertsonjay | last post by:
In mvc you separate view from controller. How do you do that in C#? Many people define an interface for a controller but isn't controller is specific to a form(gui) which all controller contains...
5
TheServant
by: TheServant | last post by:
I have recently (today) started doing something worthwhile on CodeIgniter, which is fantastic BTW. I have a problem and I can't figure out what is going wrong. I will post what I have now, but this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.