How to delete index. php in a URL using the CI framework-php Tutorial

Source: Internet
Author: User
Tags url forwarding
How does the CI framework delete the index in a URL. most of the technologies generated by php's ultimate solutions using dynamic Web technologies include indexes. php, effectively delete the inde in the URL without causing route confusion. php can make the webpage address look more friendly! Although the following sections are for the CI framework, from the perspective of its implementation principle, it is still of great reference value to solve similar problems in other cases.
Official solution

By default, the index. php file will be included in your URL:

Example.com/index.php/news/article/my_article

You can easily use the. htaccess file to set some simple rules to delete it. The following example uses the "negative" method to redirect unspecified content:

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

Note: If your project is not in the root directory, change the above sentence to RewriteRule ^ (. *) $ index. php/$1 [L].

In the preceding example, any HTTP requests other than index. php, images, and robots.txt can be directed to index. php.

My ultimate solution

However, in practice, the above solution is only applicable to servers running in the Apache environment and is not fully applicable! When the CI program is located in a non-root directory or on some virtual hosts, the preceding solution may cause errors such as "404 error" or "no input file specified. baidu has found a universal method to effectively delete the index in the URL path after referring to the liberation solution for related issues. php method. the code is as follows:

When the index is in the root directory, you can create a. htaccess file in the root directory where index. php is located and use the following code:

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

When index. php is not in the root directory, you can create a. htaccess file in the directory where index. php is located and use the following code:

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

Note: replace path_to_app with the Directory of the file where your index. php is located. assume that your index. php is placed under the tool sub-folder in the root directory. you can write it like this:

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

The above solution should solve how to effectively delete the index in the URL in the Apache environment. php problems. if you have other questions, please comment or leave a message and leave a valid contact information. I will try to solve the problem for you and notify you of the possible solution in time!

In addition, for how to effectively delete index. php in the URL in the IIS environment, refer to this article:

IIS7.5 remove the index. php web. config configuration file


Reply to discussion (solution)

I am new to the CI framework and do not know where to start.

Do? Object? The fastest, see ?? Use

I found a lot of methods and didn't even mention it. the landlord was awesome. I just solved it.

I have changed this. it is very easy to find/config. php in your app.

Change this section
$ Config ['index _ page'] = 'index. php'; $ config ['index _ page'] = '';

The framework has already done url Forwarding and does not require. htaccess.

If it is the root directory, how does path_to_app (project file) say?

I am new to the CI framework and do not know where to start.

Documents on Chinese Forum

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.