Codeigniter framework
Cristian Gilè
10 September 2008, 18:35
Hi,
i am using Codeigniter framework (www.codeigniter.com) to develop my php applications, but i'm in trouble with hiawatha.
By default, URLs in CodeIgniter are designed to be search-engine and human friendly. Rather than using the standard "query string" approach to URLs that is synonymous with dynamic systems, CodeIgniter uses a segment-based approach.
example.com/news/article/my_article
By default, the index.php file is included in URLs:
example.com/index.php/news/article/my_article
Hiawatha doesn't like this approach and return a 404 error page.
Some guy in the codeigniter forum suggest to append a ? after index.php in the url but it doesn't work.
I have also tried to set different options for the $config['uri_protocol'] directive in the config.php file (a config file of the framework):
'AUTO' Default - auto detects
'PATH_INFO' Uses the PATH_INFO
'QUERY_STRING' Uses the QUERY_STRING
'REQUEST_URI' Uses the REQUEST_URI
'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
but nothing to do.
I know, i can remove index.php using a .hiawatha file with URL toolkit but what if i want to preserve it.
Could you help me to solve this?
Cheers
Cristian
Hugo Leisink
10 September 2008, 22:14
Could you please try the following configuration and let me know if that works?
UrlToolkit {
ToolkitID = codeigniter
Match ^/index.php/.* Rewrite /index.php
RequestURI exists Exit
Match .* Rewrite /index.php
}
VirtualHost {
... your host config here ....
UseToolkit = codeigniter
}
In config/config.php use this setting:
$config['uri_protocol'] = "REQUEST_URI";
Cristian Gilè
11 September 2008, 13:41
Yes, it works!
It also seems to work with this setting:
$config['uri_protocol'] = "AUTO";
Thanks a lot.
Cristian
Cristian Gilè
7 October 2008, 19:02
Is there a way to modify this UrlToolkit in order that only the domain without segment URIs is shown in the browser address bar?
Example:
before:
www.example.com/test/index.php/controller/
after:
www.example.com
Cheers
Cristian
Hugo Leisink
7 October 2008, 21:37
The UrlToolkit can only be used to rewrite the URL entered in the URL bar in the browser to a new URL which is passed on to the webserver. It can't change the URL in the browser. It's very good it can't be changed, otherwise it would be a hell of a security bug. Just think of how people can be fooled. You think you visit www.mybank.com, but actually you are visiting www.fakebank.ru.
Cristian Gilè
8 October 2008, 11:40
I don't want to change the URL in the address bar to a new URL.
Please, visit www.nierle.com
wherever you click you see only www.nierle.com in the address bar without URI segment. So an address like http://www.nierle.com/segment1/segment2/ become http://www.nierle.com
Cheers
Cristian
Hugo Leisink
8 October 2008, 11:44
Ok, I understand. The trick they are using is not URL rewriting, but HTML frames. Just look at the source of the page. The FRAMESET tag is the trick. You are actually browsing inside a frame. Inside that frame, the URL has a URI segment, but the browser doesn't show.
Cristian Gilè
8 October 2008, 12:22
Ok, thanks.
Cheers
Cristian
Maz Solie
14 December 2008, 22:09
In my machine, the above setting works fine if I put codeigniter into root dir of my virtual host, but if I put codeigniter into subfolder, ie http://solie.dyne/codeigniter/, the main page shows as usual, but all links become 404. Can you help please?
Hugo Leisink
15 December 2008, 01:40
Please, try this configuration and let me know if it works:
UrlToolkit {
ToolkitID = codeigniter
Match ^/codeigniter/index.php/.* Rewrite /codeigniter/index.php
RequestURI exists Exit
Match .* Rewrite /codeigniter/index.php
}
Maz Solie
15 December 2008, 02:40
Thanks, actually I just discover how to resolve this, all I need is just add EnablePathInfo = yes in virtualhost section, and codeignoter works as in lighttpd and cherokee.
Yes, the above code works, but I need to hardcode codeigniter folder then.
Again, thank you and sorry for asking before read the manual thoroughly
Maz Solie
15 December 2008, 03:01
But how about to change
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
from apache into hiawatha? that code convert index.php/input/register become input/register,
Hugo Leisink
15 December 2008, 10:10
That would be
Match ^/(index\.php|images|robots\.txt) Return
Match (.*) Rewrite /index.php/$1
Maz Solie
15 December 2008, 11:11
Thanks, sure I'll try that, later at home
Maz Solie
16 December 2008, 00:12
the problem still the same, when i try to remove index.php from url ang press go,it goes to 404.
here is my config:
UrlToolkit {
ToolkitID = CI
Match ^/index.php/.* Rewrite /index.php
RequestURI exists Exit
Match (.*) Rewrite /index.php/$1
Please help me
Hugo Leisink
16 December 2008, 00:31
You said your website is located in /codeigniter/. You have tried the rules for that I supplied earlier?
Maz Solie
16 December 2008, 04:39
well, actually i'm not using your rule earlier (hardcode codeigniter folder in httpd.conf), becoz by adding EnablePathInfo the codeigniter works well, and by adding more rules, i think i can make index.php dissapear.
now, i think the conclusion is: by just adding EnablePathInfo i can't make index.php gone, except by adding codeigniter folder in the rules, is it right?
ok. so if i have 2 or more framework which are similar to codeigniter, i've to add the rules for each framework?
ls it possible in the same virtual host installing many different framework?
Hugo Leisink
17 December 2008, 11:43
I'm quite busy at the moment. I need some time to try it out myself. I will give you an answer as soon as possible.
Maz Solie
17 December 2008, 21:44
thank you Hugo
Yassen Damyanov
23 December 2008, 19:41
Maz:
It works great for me with the exact config Hugo has posted earlier in this thread. I don't need to specify index.php (I even HAVE to omit it, as it does not work with index.php for me, I get 404).
Let me know if I can be of any further help.
yassen
Hugo Leisink
23 December 2008, 20:20
I've done some testing and have found the following configuration working:
UrlToolkit {
ToolkitID = codeigniter
RequestURI exists Exit
Match .* Rewrite /index.php
}
VirtualHost {
Hostname = codeigniter.lan
WebsiteRoot = /path/to/codeigniter
StartFile = index.php
ExecuteCGI = yes
UseToolkit = codeigniter
}
set $config["uri_protocol"] to "REQUEST_URI" in system/application/config/config.php.
If you want multiple codeigniter installations in one virtual host, you must adjust your rewrite rules:
UrlToolkit {
ToolkitID = codeigniter
RequestURI exists Exit
Match /dir1/.* Rewrite /dir1/index.php
Match /dir2/.* Rewrite /dir2/index.php
}
Maz Solie
30 December 2008, 05:41
Thank you, the above config works for my two projects using codeigniter, though (sorry for repeating) we must explicitly write the DIR1 and DIR2 in main config file. So, can I just use these config for some specific directories, maybe via .hiawatha file so that these rules only applied into the respective directories ?
From hiawatha man page, I found that urlToolkit can't be applied per directory (didn't try yet). Currently, I use per virtual hosting config to handle some codeigniter or other framework (by aliasing IP). So, my point is how to appy urlToolkit into some specific directories, as I used and learn some frameworks for my projects.
Hugo Leisink
30 December 2008, 13:29
Hiawatha's URL Toolkit itself is able to use directory specific configuration. You can use the 'Call' and 'Goto' statements for that.
Example:
UrlToolkit {
ToolkitID = CI_config_1
...
}
UrlToolkit {
ToolkitID = CI_config_2
...
}
UrlToolkit {
ToolkitID = codeigniter
Match ^/dir1/.* Goto CI_config_1
Match ^/dir2/.* Goto CI_config_2
}
Is this what you are looking for?
Maz Solie
31 December 2008, 06:28
Well, the above example is so clear, but what if I put that in the .hiawatha file, so that I don't need to include "dir" for codeigniter in the main config file? just like .htaccess for clear.
Hugo Leisink
31 December 2008, 09:36
Hiawatha's URL toolkit is more than just URL rewriting. It's sort of a 'program'. Before using it, Hiawatha sort of 'compiles' the toolkit rules. It therefore requires that all the 'routines' are present. If part of the toolkit program are in .hiawatha files, Hiawatha can't compile the complete toolkit program (missing routines which are located in .hiawatha files).
A second reason is that the regular expressions take time to compile. So if I put those in a .hiawatha file, I need to recompile them everytime a file from that directory is requested. Of course I can cache the .hiawatha file. But when that file is changed, I need to do some tricky stuff to unload those configuration rules and make sure no other thread is using it.
I decided to keep it simple (and therefor stable and secure) and not to allow toolkit rules in a .hiawatha file.
Maz Solie
31 December 2008, 11:25
got it, thanks Hugo 4 your great explsnations
This topic has been closed.