Welcome Guest, Not a member yet? Register   Sign In
Yet another index.php problem
#1

[eluser]ufasoli[/eluser]
Hello everyone,
I'm really new to codeIniter and I'm having a lot of trouble removing the "index.php" file I've been looking around in the forum and tried all the configurations that I could find in the forum(including the one in the user guide) for the .htaccess file but it still does not work :

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin
    ErrorDocument 404 /index.php
</IfModule>


I've already configured as well the lines in the config.php file

Code:
$config['base_url']    = "http://localhost/field_center/";

$config['index_page'] = "";
here is my directory structure

-styles
-images
-system
--application
(all the other code igniter files & folders)
-index.php


I hope someone can help me with this

thx

ufasoli
#2

[eluser]kbauman[/eluser]
I don't really know much about re-write rules, but here is what I use that has worked fine:

Code:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|css|javascript|rte|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
#3

[eluser]Higher Logic[/eluser]
The rewrite rules suggested by CI did not work for me either, they would not parse CSS, images, and other files like that, even though I had them in the list of things not to process. Would only display text. Now, it might have had to do with the fact that I forgot to leave $config['index_page'] empty.

I don't like the index.php in there, don't even see why that is on by default, terribly ugly. Anyways, my directory structure is as follows:

CodeIgniter system files
/home/username/system

CodeIgniter index file
home/username/public_html/index.php

I prefer to keep my system files above my public_html folder (might be any of the following: httpdocs, www, etc.) for security reasons, so the only thing I have in my public_html folder is index.php, .htaccess, robots.txt, favicon.ico, and of course folders like images, css, etc.

I use this rewrite rule and it works perfectly:

[code]RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L][code]
#4

[eluser]esra[/eluser]
Try this:

Quote:Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
#5

[eluser]ufasoli[/eluser]
hi everyone and thanks for your prompt answers, none of the 2 rewrite rules that you have given me works... I really don't get it, have I forgotten something? I keep getting the "unable to find the page 404 error message" I really don't get it... any ideas?
#6

[eluser]Higher Logic[/eluser]
Do pages work normally when you have the index.php in the URL?
#7

[eluser]ufasoli[/eluser]
OK so I've finally erased and recreated my ".htaccess" file, and now it works with this rewrite condition

Code:
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|javascript|rte|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

however now I can't get the neither the CSS or the JavaScript files(I'm using the ajax for CodeIgniter library as well) to load correctly when Using the Firefox - firebug addon I check the location where the style-sheets are supposed to be retrieved from, and it's very weird because I don't have any problems with the "index()" function the css and JavaScript are retreived from

www-root/myapp/styles
www-root/myapp/javascript

but when I try to move to a different function (contact in my case) the application tries to recover the files from

www-root/myapp/controller name/styles

here is what I use to try to load my CSS and JavaScript files

Code:
&lt;link rel="stylesheet" type="text/css" href="styles/accueil.css"/&gt;

it is kind of weird...
#8

[eluser]Higher Logic[/eluser]
This line of code:

Code:
RewriteCond $1 !^(index\.php|images|css|javascript|rte|robots\.txt)

This items separated by a pipe are files and/or directories that you don't want CI's index.php file to handle. That would be everything in the images, css, javascript, and rte directories, and the robots.txt file.

So unless you have those directories, you don't need to list them. Something like this would be better:

Code:
RewriteCond $1 !(.jpg|.gif|.png|.swf|.css|.js|.txt)$

(I believe that is right, you don't want it to handle files that end in those extensions)

[quote author="ufasoli" date="1188756624"]however now I can't get the neither the CSS or the JavaScript files(I'm using the ajax for CodeIgniter library as well) to load correctly when Using the Firefox - firebug addon I check the location where the style-sheets are supposed to be retrieved from, and it's very weird because I don't have any problems with the "index()" function the css and JavaScript are retreived from

www-root/myapp/styles
www-root/myapp/javascript

but when I try to move to a different function (contact in my case) the application tries to recover the files from

www-root/myapp/controller name/styles[/quote]

Try using your absolute path instead of the relative one:

Code:
&lt;link rel="stylesheet" type="text/css" href="/styles/accueil.css" /&gt;

Notice the forward slash immediately before the directory? That means it should look for a styles directory starting from the public root of your site (e.g. domain.com). If your CSS stylesheet and JavaScript files are setup like you mentioned above, then you need to do this:

Code:
&lt;link rel="stylesheet" type="text/css" href="/myapp/styles/accueil.css" /&gt;

...or this for JS:


The reason it works when you're on the index page is because the way you have the path setup, it is looking for a sub-directory from the root, and the myapp directory just happens to be there. If you're in a sub-directory though, it's trying to find another sub-directory called myapp that does not exist.
#9

[eluser]ufasoli[/eluser]
GREATTTT it finally works!!!!!! thank you all so much for your help

here is my .htaccess file if it can help anyone

Quote:Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !(.jpg|.gif|.png|.swf|.css|.js|.txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

as user 'Higher Logic' suggested whenever I need to load an image I use the following syntax :

Code:
&lt;link rel="stylesheet" type="text/css" href="/myapp/styles/accueil.css" /&gt;

thank you all once again




Theme © iAndrew 2016 - Forum software by © MyBB