How the CI framework removes the ultimate solution for index.php in URLs

Source: Internet
Author: User
Tags url forwarding
How the CI framework removes the ultimate solution for index.php in URLs
The technology generated by the Dynamic Web page technology mostly contains index.php, in the premise of not causing confusion of the route, effectively delete the URL inde.php can make the webpage address look more friendly! The following paragraphs are for the CI framework, but from the perspective of its implementation, In other cases, the resolution of similar problems still has a greater reference value.
Official Solutions

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

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

You can easily remove it by using the. htaccess file to set some simple rules. The following is an example of using the "negative" method to redirect non-specified content:

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

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

In the above example, any HTTP requests that can implement any non-index.php, images, and robots.txt are directed to index.php.

My Ultimate Solution

However, in practice, the above scheme is only applicable to the server running in the Apache environment and does not have sufficient universal applicability! When the CI program is located on a non-root directory or on some virtual hosts, the above solution causes "404 error" or "No input file specified" And so on. After Baidu has consulted the relevant issues of the liberation Program, found a common with the effective removal URL path in the index.php method, the code reference is as follows:

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

Rewriteengine on
Rewritecond $!^ (index\.php|robots\.txt)
Rewriterule ^ (. *) $/index.php?/$1 [L]

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

Rewriteengine on
Rewritecond $!^ (INDEX\.PHP|IMAGES|ROBOTS\.TXTL)
Rewriterule ^ (. *) $/path_to_app/index.php?/$1 [L]

Note Replace the Path_to_app with the directory where your index.php files are located. Suppose your index.php is placed under the tool subfolder of the root directory, you can write:

Rewriteengine on
Rewritecond $!^ (INDEX\.PHP|IMAGES|ROBOTS\.TXTL)
Rewriterule ^ (. *) $/tool/index.php?/$1 [L]

The above solution should be able to solve the Apache environment how to effectively delete the URL in the index.php problem, if there are other issues, please comment or leave a message and left a valid contact. I will try to resolve it for you and notify you of possible solutions in time!

In addition, you can refer to this article for information on how to effectively remove index.php from URLs in the IIS environment:

IIS7.5 removing the index.php Web. config configuration file
------Solution--------------------
The first knowledge of the CI framework, I do not know where to begin.
------Solution--------------------
The quickest thing to do is to read books.
------Solution--------------------
Found a lot of methods, did not mention the idea, the landlord to force, I will solve the
------Solution--------------------

------Solution--------------------
This I changed, very simple, in your app to find/config/config.php

Change this paragraph
$config [' index_page '] = ' index.php'; for $config [' index_page '] = ';

The framework has already done URL forwarding, not required at all. htaccess
  • 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.