ThinkPHP uses the Rewrite rules of the. htaccess file to hide index. php in the URL.

Source: Internet
Author: User
ThinkPHP uses the Rewrite rules of the. htaccess file to hide index. php in the URL and remove index. php from the URL.

ThinkPHP, as a PHP framework, is a single portal, so its original URL is not so friendly. However
ThinkPHP provides various mechanisms to customize the desired URL format. in combination with the Apache. htaccess file, ThinkPHP can also

Customized and user-friendly SEO

The. htaccess file is a configuration file on the Apache server. it is responsible for the webpage configuration under the relevant directory. We can use. htaccess
File Rewrite rules to hide the index. php text in the ThinkPHP URL

(That is, the portal file), which is also the ThinkPHP URL
The first step of pseudo-static.

For example, the original URL

Http: // php/Index/insert

Remove index. php
And then changed:

Http: //

In this way, it becomes
Http: // common URL format of server address/application module name/operation name [/variable parameter.
Change Apache httpd. conf
Configuration file

Tip: If the configuration is performed on the VM provider, configure steps 3 and 4 directly, because the space supporting. htaccess has been configured in the previous two steps.

Open in editor
The Apache configuration file httpd. conf (this file is located in the Apache installation directory Apache2conf) and is modified as follows ,.
I. loaded

Confirm that the module is loaded (remove the # before the following configuration ):

Rewrite_module modules/

II. change AllowOverride configuration

Change to read
The Directory of the. htaccess file. comment out the original Directory:

# Group/Apache2/htdocs ">

AllowOverride None is AllowOverride FileInfo Options
The changed configuration is as follows:

# Group/Apache2/htdocs ">

FileInfo Options

. Htaccess is controlled based on directories, E:/html/myapp> indicates the directory where the. htaccess file needs to be read.
. If the VM provides

. Htaccess control, which is generally configured.
3. add the. htaccess file Rewrite

Create. htaccess in the directory where index. php needs to be hidden (E:/html/myapp in this tutorial, that is, the directory where the entry file is located ).
File and write the following rule code:


# Do not display index. php

! -D
RewriteCond % {REQUEST_FILENAME }! -F
RewriteRule ^ (. *) $ index. php/$1
[QSA, PT, L]

If the website already has. htaccess
File to add the configuration rules for this section. If the file cannot be created (cannot be created on Windows), you can download the file from this site, but this file is only configured to hide
Index. php

Click here to download the rule.
4. change the project configuration file

Edit the project configuration file Conf/config. php and set
Set the URL mode to 2 (Rewrite mode ):

'URL _ model' => 2,

So far, the configuration has been completed. After saving the configuration files, restart
Apache server, delete the project cache file under the Runtime directory, and hide index. php in the browser.
After the address test is successful:

Http: //

If the access is successful, use
Hide index. php
The configuration of the entry file is successful.

Read more

ThinkPHP system configuration
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: 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.