Remove index.php from the default URL of the PHP framework CI

Source: Internet
Author: User
Tags php framework codeigniter

CI in the default rewrite URL is similar to this

For example your CI root directory is under /codeigniter/ , your below level two URL is similar to this http://localhost/CodeIgniter/index.php/welcome.

Not too good-looking, how to take out the index.php?

Here's how to fix it:

The first step:

Apache Url Rewrite Configuration (php pseudo-static)

Check if the following code exists in conf/httpd.conf in Apache:

#LoadModule Rewrite_module modules/mod_rewrite.so

Remove the # from the front of the loadmodule.

Step Two:

Add. htaccess (and application, system in one directory) at the site root.

The contents are:

Rewriteengine on   rewritecond $!^ (index\.php|images|robots\.txt)   rewriterule ^ (. *) $/index.php/$1 [L]

Note:

1, pay attention to/index.php/$1 according to your directory (Web directory, such as http://www.domain.com/index.php) the actual situation to be determined.

For example, the site root directory is/ci/index.php to write/ci/index.php/$1

2. Rewritecond $!^ (index\.php|images|robots\.txt)

The above code means to exclude certain directories or files, so that these directories will not be rewrite to index.php, which is generally used in pictures, JS, CSS and other external resources. This means that non-PHP code should be excluded. (Here I ruled out the images directory and the robots.txt file, of course index.php should also be excluded)

Step Three:

Modify application/config.php

Find $config[' index_page '] = "index.php";

Modified to: $config [' index_page '] = "";

Fourth Step:

In the httpd.conf file:

AllowOverride None

Switch

AllowOverride All

Note: If you do a virtual site, do a multisite configuration in httpd-vhosts.conf, just like me:

<virtualhost *:81> documentroot "D:/wamp/www/nxtv" ServerName bayi <directory "D:/WAMP/WWW/NXTV" >  Options followsymlinks  allowoverride all  Require all granted </Directory></VirtualHost>< VirtualHost *:82> documentroot "d:/wamp/www/codeigniter220" ServerName localhost:82 <directory "d:/wamp/www/ codeigniter220 ">  Options followsymlinks  allowoverride all  Require all granted </Directory>

Remember to change allowoverride None to allowoverride all, I'm here to suffer. =

Remove index.php from the default URL of the PHP framework CI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.