Home > Backend Development > PHP Tutorial > Analysis of how to remove index.php_PHP tutorial in CodeIgniter URL

Analysis of how to remove index.php_PHP tutorial in CodeIgniter URL

WBOY
Release: 2016-07-21 15:02:25
Original
960 people have browsed it

The default rewrite URL of CI is similar to this. For example, your CI root directory is under /CodeIgniter/, and your secondary URL below is similar to http://localhost/CodeIgniter/index.php/welcome. It doesn’t look good. How can I remove the index.php in it?

1. Open the apache configuration file, conf/httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so, and remove the # before the line.
Search for AllowOverride None (there are many places in the configuration file), look at the comment information, and change the line information in the relevant .htaccess to AllowOverride All.

2. In the root directory of CI, that is, in the directory at the same level as index.php and system, create .htaccess. Directly creating the file name will not succeed. You can create Notepad first. file, just save it as a file with this name. The content is as follows (also introduced in the CI manual):

Copy code The code is as follows:

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

If the file is not at the root of www directory, for example mine is: http://www.nowamagic.net/CodeIgniter/, the third line needs to be rewritten as RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L].
In addition, there are js folders and css folders in the same directory of my index.php. These need to be filtered and removed. The second line needs to be rewritten as: RewriteCond $1 !^(index.php|images|js| css|robots.txt)

3. Change $config['index_page'] = "index.php"; in the CI configuration file (system/application/config/config.php) config['index_page'] = ""; .
Copy code The code is as follows:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327910.htmlTechArticleThe default rewrite url of CI is similar to this. For example, your CI root directory is under /CodeIgniter/, Your secondary URL below is similar to http://localhost/CodeIgniter/index.php/welcome. No...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template