Eliminating the index segment in a URL (htaccess) |
[eluser]tim042829[/eluser]
FYI: I am an experienced web developer (reference http://ellislab.com/forums/viewthread/162794/) but I am new to PHP and codeIgniter. I am working in a linux environment. See: http://blog.insicdesigns.com/2009/02/bui...rk-part-1/ With the following .htaccess: Code: RewriteEngine on http://localhost/CodeIgniter/index/test/ Is there a way to eliminate the '/index/' segment (path part) from the URL above? I'm a noob if not a boob when it comes to .htaccess. TIA Tim
[eluser]bretticus[/eluser]
"test" is your controller file so your URL should be: Code: http://localhost/CodeIgniter/test/ htaccess will rewrite that internally as: Code: http://localhost/CodeIgniter/index.php/test/ according to your Rewrite code. CodeIgniter will automatically call your index method/function in your test controller unless you specify otherwise. Please note: Code: http://localhost/CodeIgniter/test/ and Code: http://localhost/CodeIgniter/test/index are equivalent. Anything that needs to work outside of the controller/method URL convention, can be handles via routes (no need to update htaccess.) See Routing
[eluser]tim042829[/eluser]
[quote author="bretticus" date="1280895398"]"test" is your controller file so your URL should be: Code: http://localhost/CodeIgniter/test/ Actually, the URL above is generating a 404 error Quote:htaccess will rewrite that internally as:Calling the previous URL is successful. Quote:CodeIgniter will automatically call your index method/function in your test controller unless you specify otherwise.And that previous URL request is also generating a 404 error. Quote:Anything that needs to work outside of the controller/method URL convention, can be handles via routes (no need to update htaccess.)I appreciate the response. With the 404 error from the http://localhost/CodeIgniter/test/ URL, I would then guess that there is something wrong with my code or with the .htaccess code, or in the apache configuration itself. Any ideas where to look?
[eluser]bretticus[/eluser]
Quote:I appreciate the response. With the 404 error from the http://localhost/CodeIgniter/test/ URL, Yes, modify your system/application/config/config.php to remove index.php from your url. See details in the wiki.
[eluser]tim042829[/eluser]
Thank Betticus, I had thought of config.php following my post. I will look at wiki and report back (probably tomorrow). regards tim
[eluser]cseguin[/eluser]
Hi tim042829, I have a similar problem, any luck? we are waiting for you to report back :-) regards
[eluser]bretticus[/eluser]
Posting the same thing I responded to @cseguin with: Quote:The following config item: Make sure you have mod_rewrite enabled locally.
[eluser]tim042829[/eluser]
[quote author="cseguin" date="1280953714"]Hi tim042829, I have a similar problem, any luck? we are waiting for you to report back :-) regards[/quote] No luck! sigh.. I followed the instructions at http://codeigniter.com/wiki/mod_rewrite/ to the best of my ability. Mode rewrite is enabled on my machine. I changed the AllowOverride directives in my apache default and default-css files form None to FileInfo. I used the .htaccess file as specified in that page. A couple of comments here: I've done things the 'hard way' for 14 years now. I want php to be the 'easy way', and furthermore, I am reluctant to do any system-wide mods to apache. If it ain't easy, I would find another way. And I did. Just to test, I activated the following line in config.php to Code: $config['index_page'] = "akwebsoft.php"; and copied index.php as akwebsoft.php. Now I can request Code: http://localhost/CodeIgniter/akwebsoft/test Maybe I will revisit that issue when I have graduated from noobhood. Sorry, tim
[eluser]tim042829[/eluser]
I believe that I have it working now. mod_rewrite seems to be successfully implemented. 1)Set AllowOverride => all (instead of fileinfo) 2)Symlinked /etc/apache2/mods-available/rewrite.load to /etc/apache2/mods-enabled/rewrite.load And it worked. That's ubuntu 10.04, I believe that (for instance) slackware setup is different. cheers tim |
Welcome Guest, Not a member yet? Register Sign In |