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