2

I am new the CodeIgniter and the index.php is being a pain in the ass.

I want some friendly URLs but my website is in a subfolder.

I installed the clean CodeIgniter installation, added another view for test purposes and this is what I am getting.

Page 1
http://www.example.com/webadmintest/
http://www.example.com/webadmintest/index.php/welcome/index

Page 2
http://www.example.com/webadmintest/index.php/welcome/byebye

This works perfect.

Now in the config file I changed to this:

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

And added this in the .htacces in the application folder(I don't know if this is the place or the root CodeIgniter folder)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

I stil can load the previous links but if I try to go to this ones it send me to the main www.example.com page.

 Page 1
    http://www.example.com/webadmintest/
    http://www.example.com/webadmintest/welcome/index

 Page 2
 http://www.example.com/webadmintest/welcome/byebye

I have also tried using:

$config['base_url'] = '/webadmin/';

and

RewriteBase /webadmintest/

and

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

As you can see this is not the typical problem, I mean probably if this was a standalone website I probably wont have this problem, but the requirements need the website to be a subfolder of a main website.

Thanks

bucur89
  • 170
  • 1
  • 13
  • possible duplicate of [Remove index.php From URL - Codeigniter 2](http://stackoverflow.com/questions/5155333/remove-index-php-from-url-codeigniter-2) – Kumar V Jan 07 '14 at 15:30
  • You want to remove the file index.php or you just want it removed from the URLs? – Christian Dechery Jan 07 '14 at 15:31
  • I want it removed from the URLs – bucur89 Jan 07 '14 at 15:57
  • I have tried the piece of code in kumar_v's answer and in someway it is working. My main page loads through this two links `www.example.com/backend/` `www.example.com/backend/main/` But a second page throud this ones doesn't load `www.example.com/backend/clients` `www.example.com/backend/clients/index` and it used to load as `www.example.com/backend/index.php/clients/index` – bucur89 Jan 07 '14 at 16:03

2 Answers2

1

I guess you have the mod_rewrite in your, if not Get mod_rewrite here

In the app folder > config folder > config.php

$config['index_page'] = 'index.php'; -> $config['index_page'] = '';
Hubert
  • 169
  • 6
0

Finally found the answer.

This applies to everyone who has the CodeIgniter in a subfolder

First of all the \subfolder\application\config\config.php

You have to find these lines and change it with these:

$config['base_url'] = 'http://www.example.com/subfolder/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

Next you have to modify your \subdfolder\application.htaccess with this:

Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /subfolder/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    #When your application folder isn't in the system folder

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

And then create a new .htaccess in \subfolder.htaccess and add this code:

RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

Thanks to @saurabh2836 adn @Robin Morgan

bucur89
  • 170
  • 1
  • 13