Configuring the thinkphp pseudo-static URL in the Apache server

Source: Internet
Author: User

Thinkphp, as one of the most popular PHP frameworks in the country, has attracted more and more developers to use her as an infrastructure for projects because of the ease with which she develops applications. Like my PHP base is not very good, you can also use her to complete a smarty pants project.

Share some of the things you need to know about using thinkphp.

Remove the index.php from the URL

Thinkphp is a single entry, the default URL is not very friendly. However, Thinkphp provides a variety of mechanisms to customize the required URL format, with Apache inside the. htaccess file, it is possible to customize the user-friendly SEO URL address.

The. htaccess file is a configuration file in the Apache server that is responsible for the Web page configuration under the relevant directory. We can use the Rewrite rules of the. htaccess file to hide the index.php file in the thinkphp URL (that is, the portal file), which is also the first step of thinkphp URL pseudo-static.

For example, the original URL is:

Http://127.0.0.1/index.php/Index/insert

After removing the index.php, it becomes:

Http://127.0.0.1/Index/insert

As a result, it becomes a common URL format of http://server address/Application module name/action name [/variable parameter].

Change Apache httpd.conf configuration file

Tip: If you are configuring in a virtual host, configure the third to fourth step directly because the support. htaccess space has been configured for the first two steps. Use the editor to open the Apache configuration file httpd.conf (the file is located in the Apache installation directory apache2conf) and modify it as follows.

First, load the mod_rewrite.so

Verify that the mod_rewrite.so module is loaded (remove the # number before configuration):
LoadModule Rewrite_module modules/mod_rewrite.so

Second, change the allowoverride configuration

Change the directory where the. htaccess file needs to be read and comment out the original directory:
#<directory "C:/Program files/apache Group/apache2/htdocs" >

Change allowoverride None to allowoverride FileInfo Options, and the changed configuration is as follows:
#<directory "C:/Program files/apache Group/apache2/htdocs" >

AllowOverride FileInfo Options

The. htaccess is directory-based, which means that the directory to which the. htaccess file needs to be read is configured according to the actual specific Apache parsing directory. If the virtual host is provided with. htaccess control, it is generally configured.

Iii. Add. htaccess file Rewrite rules

Create the. htaccess file in the directory where you want to hide index.php (in this tutorial, the directory where the portal file is located), and write the following rule code:

Rewriteengine on

#不显示index. php
Rewritecond%{request_filename}!-d
Rewritecond%{request_filename}!-f
Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]

Iv. changing the project configuration file

Edit the Project Profile conf/config.php, configure the URL pattern to 2 (rewrite mode):
' Url_model ' =>2,

At this point, the individual configurations are complete. After saving each configuration file, restart the Apache server and delete the project cache file under the Runtime directory, and the address test after the browser accesses the hidden index.php is successful:

Http://127.0.0.1/html/myapp/Index/index

If the access is successful, then the configuration of the index.php portal file using the Rewrite rules of the Apache. htaccess file is successful.

Life Network http://www.onesheng.cn

Configuring the thinkphp pseudo-static URL in the Apache server

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.