Hide index. php and thinkphpindex. php In the ThinkPHP framework.

Source: Internet
Author: User

Hide index. php and thinkphpindex. php In the ThinkPHP framework.

The configurations written in this article have been tested on ThinkPHP3.2.2. It is also compatible with other versions.

First, modify the configuration file:

'Url _ CASE_INSENSITIVE '=> true, // The default value is false, indicating that the URL is case-sensitive. true indicates that the URL is case-insensitive.
'Url _ model' => 2, // URL access mode. Optional parameters: 0, 1, 2, and 3, which represent the following four modes:
// 0 (normal mode); 1 (PATHINFO mode); 2 (REWRITE mode); 3 (compatible mode): PATHINFO mode by default

Nginx

Recommended:

location / {try_files $uri $uri/ /index.php?s=$uri&$args;}

If the first $ uri does not exist, access $ uri/. If $ uri/does not exist, access/index. php? S = $ uri & $ args. It can be followed by many.

Try_files Syntax: try_files file1 [file2... filen] fallback default value: no scope: location

For example:

try_files $uri = 404 

What does it mean? The uri cannot be accessed successfully. Well, you can get 404.

However, most of the articles found on the Internet are configured as follows:

location / {if (!-e $request_filename) {rewrite ^/(.*)$ /index.php?/$1 last;break;}}

Actually not feasible.

Apache

Create a. htaccess file in the root directory:

<IfModule mod_rewrite.c>Options +FollowSymlinksRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule> 

IIS Environment

If your server environment supports ISAPI_Rewrite, you can configure the httpd. ini file and add the following content:
RewriteRule (. *) $/index \. php \? S = $1 [I]

In the later version of IIS, you can configure web. Config and add a rewrite node in the middle:

<rewrite><rules><rule name="OrgPage" stopProcessing="true"><match url="^(.*)$" /><conditions logicalGrouping="MatchAll"><add input="{HTTP_HOST}" pattern="^(.*)$" /><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /><add input="{REQUEST_FILENAME}” matchType="IsDirectory" negate="true" /></conditions><action type="Rewrite" url="index.php/{R:1}" /></rule></rules></rewrite> 

Appendix

Complete Nginx Configuration

test.com.confserver{listen 80;server_name test.com;index index.php index.html;root /wwwroot/test.com/;# unless the request is for a valid file (image, js, css, etc.), send to bootstraplocation / {try_files $uri $uri/ /index.php?s=$uri&$args;}location ~ \.php{fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;set $path_info "";set $real_script_name $fastcgi_script_name;if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {set $real_script_name $1;set $path_info $2;}fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;fastcgi_param SCRIPT_NAME $real_script_name;fastcgi_param PATH_INFO $path_info;}location /status {stub_status on;access_log off;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires 24h;}location ~ .*\.(js|css)?${expires 12h;}if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}access_log logs/test.com_access.log main;error_log logs/test.com_error.log notice;}
Articles you may be interested in:
  • Modify apache configuration file to remove index. php from thinkphp url
  • Nginx configure PATHINFO to hide thinkphp index. php

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.