Remove index.php From URL - Codeigniter 2

2019-01-01 15:48发布

I am having trouble removing index.php from my URLs in Codeigniter. I've made a few websites with Codeigniter 1.7 and the .htaccess code I used doesn't work in 2.

I have tried using

<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>

and

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

</IfModule>

I've also tried it without RewriteBase / in.

I have changed the $config['uri_protocol'] to REQUEST_URI and QUERY_STRING and nothing.

I have set $config['index_page'] = "";

The file structure is 192.168.0.130/(site)/ so it must be going back to the root of the server and can't find the index.php file.

All of the controllers I have made can be reached by putting 192.168.0.130/(site)/index.php/testcontroller

Thank you.

Apologies if this has been asked before - I have looked and tried what I could see.

Edit:

I should also add that I changed the default folders to be

application

CI-2.0

index.php

and changed the paths in index.php to be correct.

7条回答
查无此人
2楼-- · 2019-01-01 16:43

Try the first code block you posted, but instead of /index.php try using /(site)/index.php (obv replacing (site) with whatever your site folder is named).

查看更多
登录 后发表回答