thinkphp how to get rid of index.php_php tutorials in URLs

Source: Internet
Author: User
The URL of the app developed with thinkphp usually takes a index.php, and if we need pseudo-static or SEO optimization, this is very bad to see and meaningless. So how do we get rid of the index.php in the Thinkphp app URL?

For this problem we can be resolved by URL rewrite, of course, this is required to open the Server Url_rewrite module. So make sure your server is turned on or open url_rewrite before following the steps below.

(1) If Url_rewrite is not turned on, you will need to find the httpd.conf in Apache and find the following line:

#LoadModule Rewrite_module modules/mod_rewrite.so

Remove the warning from the front and continue to find the following sentence:

AllowOverride None

Change all the found above statements to: allowoverride all

The above modifications are complete and then the Apache server can be restarted.

(2) Create a new. htaccess file under the app's root directory. Add the following code to the file:

 
  
   
  Rewriteengine Onrewritecond%{request_filename}!-drewritecond%{request_filename}!-fRewriteRule ^ (. *) $ index.php/$1 [Qsa,pt,l]
 
  

In fact, the above has been implemented to remove the URL in the index.php character direct access to the application. But the only two-step operation will also be a problem is the thinkphp constant __url__ or will automatically take index.php this string, the solution to the problem is to add a configuration file in the project as follows:

' Url_model ' = ' 2 '

At this point the thinkphp app URL index.php completely disappeared.

Note: You cannot build directly under Windows. htaccess such a file, you can create a file (for example: Www.phpernote.com.txt), and then enter the following command in DOS:

Rename Www.phpernote.com.txt. htaccess

Articles you may be interested in

    • How to remove the index.php string from the URL of the website CodeIgniter developed
    • PHP to add a backslash in front of the reason and PHP to remove the backslash method, three ways to close the PHP magic quotes
    • Summary of system constants in the thinkphp Action controller
    • thinkphp print the last SQL statement
    • The difference between execute and query methods in thinkphp
    • PHP BOM Removal tool, PHP batch removal of BOM code
    • The last record in the thinkphp template that determines the volist loop
    • thinkphp like query

http://www.bkjia.com/PHPjc/764144.html www.bkjia.com true http://www.bkjia.com/PHPjc/764144.html techarticle The URL of the app developed with thinkphp usually takes a index.php, and if we need pseudo-static or SEO optimization, this is very bad to see and meaningless. So ...

  • Related Article

    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.