0

Okay so I know that a lot of people have been asking the same or similar questions, but I don't seem to find a solution that works for my project. So please don't put this as a duplicate.

I have a website made with codeigniter. It was running just fine without the index.php in the url. So the rewrite was successfull. Until a few days ago: all of a sudden the admin area (/admin) returned a 404 and was only accessible by the path '/index.php/admin'. The rewrite code that once used to work didn't do a thing anymore.

And know I'm back at the start -> the problem is that I cannot delete the index.php from my url.

I tried so many things that I don't know what to do anymore.

The application is stored under 'public_html/application/... The image below is inside the application folder where the .htaccess file and index.php are. Is this the right location to change the .htaccess?

enter image description here

I tried rewriting the .htaccess but without success:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^CI/(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots|css\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

My config file:

$config['base_url'] = 'http://www.mysite.be/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

Routes.php:

$route['default_controller'] = "c_home/index";
$route['404_override'] = '';
$route['admin'] = "c_home/adminpanel";
$route['logout'] = "c_login/logout";

Does anybody have a clue what is going on or how this can be fixed?

Thanks in advance!

1
  • Are you getting any errors in your apache logs? And double check mod rewrite is enabled just in case. Commented Feb 4, 2014 at 17:17

5 Answers 5

1

The .htaccess should be in the public_html directory -- ie: one level up from the current location. The index.php is presumably in public_html already and The index.* you have in the picture is index.html -- as it should be. If .htaccess is in the right place per the above, then this .htaccess code will work:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]  
Sign up to request clarification or add additional context in comments.

6 Comments

Okay this made some progress but not yet there. I moved the .htaccess and now I'm redirected to the homepage whenever I type /admin behind my url.
try this route: $route['admin'] = "c_home/adminpanel/index";
more-specifically, you ended up at the default route because you are getting a 404 on admin. i'm guessing you are trying to get to the index function of the adminpanel controller class and if so then try this route: $route['admin'] = "c_home/adminpanel/index";
Hmm c_home is the controller and adminpanel is the function im trying to get. What would be the correct routing in this case?
And if I put $route['default_controller'] = "c_home/adminpanel"; then the routing works, the admin area is shown if I type just the url. But when I do $route['admin'] = "c_home/adminpanel"; it doesnt do anything if I add /admin to the url.
|
1

So I have been messing around with this and finally made it work

For this I made changes to the htaccess and controllers.
I changed the admin function to a new controller and changed this in the routes.php

new routing

$route['admin'] = "c_login/index";

new .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 

Comments

0

Try set

$config['uri_protocol'] = 'PATH_INFO'

And set

$config['enable_query_strings'] = FALSE;

1 Comment

in combination with what .htaccess?
0

If we need a remove /index.php from url in codeigniter Than

application/config/config.php

  $config['index_page'] = '';

  $config['uri_protocol'] = 'REQUEST_URI';

add .htaccess file at root directory of project

RewriteEngine on
RewriteBase /[Your project folder name]/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Now you can access like

http://example.com/controller/method

May it's helpfull for you

Comments

-1

I don't know what the heck you're doing with all that code, but I just put this in my .htaccess file:

RewriteRule ^(.*)$ /index.php?/$1 [L]

And boom.

3 Comments

This solution is not working for me either. Pretty much the same as the 4th block I tried. Don't know how this can work without RewriteEngine on or anything.
I don't think it's fair to vote down a comment because it doesn't work with your overly-elaborate setup. Install a blank CI and try it - you'll find it works.
I did not vote down your answer, someone else did :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.