0

I've been trying for hours and could not make it work. Searched for answers everywhere, and nothing seems to solve my problem.

I even tried the solutions described here: Remove index.php in codeigniter 2.1.0. No luck at all.

I have set the config['index_page'] as ''.

My .htaccess is on the root folder (where the sys and app folders are) and is written like this:

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

Still, the only way I can access my controller methods is with the goddamn index.php in the url. And yes, my apache conf has mod rewrite enabled.

ANY HELP would be incredibly nice.

EDIT

I´ll add some more info, maybe it's relevant.

  • I´m using ZendServer.
  • I´m working at localhost by now.
Community
  • 1
  • 1
darksoulsong
  • 13,988
  • 14
  • 47
  • 90
  • 1
    I have the same problem, I looked everywhere but I couldn't find anything that worked, so I create a hook for the time being, until I find a proper solution: if(strstr($_SERVER['REQUEST_URI'],'index.php')): $url = str_replace('index.php/', '', $_SERVER['REQUEST_URI']); header("HTTP/1.1 301 Moved Permanently"); $url = ltrim($url, '/'); header("Location: http://www.domain.com/$url"); exit(); endif; I will follow this question, to see if someone helps. – jonaypelluz Nov 07 '12 at 12:28
  • Nice, I will try that when I got the time. But I would rather do this using a htaccess file. I just wanted to figure out wtf it doesn't works here. – darksoulsong Nov 08 '12 at 15:17
  • what is the url your trying to load? – itsme Nov 24 '12 at 17:31

5 Answers5

3
RewriteEngine On
RewriteBase /yourdirectoryname/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]

I have no experience on ZendServer, but tonight I also got this problem on localhost using xampp (without ZendServer), and finally got it worked :

  1. check your httpd.conf, and make sure "LoadModule rewrite_module modules/mod_rewrite.so" line is not commented.
  2. open config.php, set $config['base_url'] = 'http://localhost/yourdirectoryname/'
  3. still in config.php, set $config['index_page'] = ''
  4. create .htaccess file on the same directory with your index.php (in my case, htdocs/yourdirectoryname)
  5. the content of that .htaccess file is as above
1

I have no experience with code igniter, but if I understand correctly you are trying to serve something like /index.php/my-page to the user, without the need for him to prepend index.php to it?

If I'm correct, you could try something like this:

RewriteBase /                                 # make sure we always rewrite from within the root directory

RewriteCond %{REQUEST_FILENAME} !-f           # make sure the request is not to an existing file
RewriteCond %{REQUEST_FILENAME} !-d           # nor an existing directory
RewriteCond %{REQUEST_FILENAME} !^index\.php  # make sure we do only interpret requests that DO NOT start with index.php
RewriteRule ^(.*)$ index.php/$1 [L,QSA]       # interpret request as if it were to index.php/...

# make sure we do only interpret requests that DO start with index.php
RewriteRule ^index\.php/(.*)$ $1 [L,R,QSA]    # redirect user to new URL, which will be handled by the first rewriterule

Keep me posted whether this works or not

Tom Knapen
  • 2,277
  • 16
  • 31
  • @darksoulsong Do you get an error, or what is it (not) doing? Did I correctly understand your problem? – Tom Knapen Nov 08 '12 at 17:01
  • Yes, I think you did understand alright. I put your code into the .htaccess file. But everytime I try to access the site locations using a clean url (for example: "example.local/contact/";) I get a "page not found" error. But everything works if I include the "index.php" into the url ("example.local/index.php/contact/";). I feel like the .htaccess file is being totally ignored by the server. – darksoulsong Nov 09 '12 at 07:32
1

try this one, i've used this on many hosts anywhere , check:

RewriteEngine On
RewriteBase /yoursitedirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

if is not enought then go to config.php file and search for this line:

|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| '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
|
*/
$config['uri_protocol'] = 'AUTO';

i use AUTO but you maybe need to switch that to REQUEST_URI or QUERY_STRING, try

itsme
  • 48,972
  • 96
  • 224
  • 345
0

I finally managed to work this out. Thanks for all the answers, special thanks to @ddanurwenda. His rewrite rules were the only ones that solved my problem.

There was an Apache config that I had overlooked: I changed this line (from httpd.conf):

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

To the following:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
    Satisfy all
</Directory>

That configuration were keeping my htaccess file from being read.

darksoulsong
  • 13,988
  • 14
  • 47
  • 90
0

This is what I use and works. Use this code in your .htaccess

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

Just make sure the .htaccess is in your root folder. (ie: xampp/htdocs)

Then in your config.php(application\config) replace config['index_page']='index.php' to config['index_page']=''.

Robert
  • 186
  • 5
  • 13