How to remove index.php from CodeIgniter URL

  • 2020-06-19 09:56:27
  • OfStack

CI default rewrite url is like this, such as your CI root directory is under/CodeIgniter /, you of the following 2 url http on something like this: / / localhost CodeIgniter/index php/welcome. It's not very nice. How can I get index.php out of it?

1. Open the apache configuration file, conf/ httpd.conf:
LoadModule rewrite_module modules/ es25EN_rewrite.so, drop the # before the line.
Search for AllowOverride None (multiple places in the configuration file), look at the comments, and change the relevant.htaccess line to AllowOverride All.

2. In the root directory of CI, that is, in the directory of the same level of ES37en.php, system, htaccess, directly establishing the file name will not succeed, you can first create notepad file, and save as the file name. The contents are as follows (also described in the CI manual) :

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

If the file is not under the root directory of www, for example to me is: http: / / www nowamagic. net CodeIgniter /, line 3 need to rewrite RewriteRule ^ (. *) $/ CodeIgniter/index php [L] / $1.
In addition, my index. php folder has js folder and css folder under its sibling directory, these need to be filtered out, the second line needs to be changed to: RewriteCond $1! ^ (index \. php | images | js | css | robots \. txt)

3. Will CI configuration file (system application/config/config php) in $config [' index_page] = "index. php"; Will $config [' index_page] = ""; .

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------

| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.

*/
$config['index_page'] = '';

Restart apache

Related articles: