nginx-thinkphp How to implement URL rewrite

Source: Internet
Author: User
thinkphp How to Implement "http://localhost/index.php?/module/Operation &quo ... Change to "http://localhost/module/operation"
I want to change the URL into this form, it will look comfortable, but I do not know how to achieve.
Is the CONIFG inside add parameter, or in Nginx inside with rewrite?

Reply content:

thinkphp How to Implement "http://localhost/index.php?/module/Operation &quo ... Change to "http://localhost/module/operation"
I want to change the URL into this form, it will look comfortable, but I do not know how to achieve.
Is the CONIFG inside add parameter, or in Nginx inside with rewrite?

1. In the configuration file, change the URL mode to

' Url_model '          = ' 2 ',//rewrite mode

2.Apache Server, save the following content as a. htaccess file in the sibling directory of the portal file

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

Configuration in nginx.conf

Location/{//... omit part of the code   if (!-e $request _filename) {   rewrite  ^ (. *) $/index.php?s=$1 last  ;   break;    } }

Resources:
Http://doc.thinkphp.cn/manual/url_rew ...
Http://doc.thinkphp.cn/manual/hidden_ ...

Suggest landlord to look at the manual side first, after all, this is the basis of things.

In a rewrite way.
Official Document: Hide index.php

This needs to be in the Nginx configuration inside the rewrite.

The original format ensures that the framework can function properly without the rewrite module on the server (Apache/nginx, etc.).

The rewrite can resemble:

location/your_app/{    if (!-f $request _filename) {#如果请求到css等资源则略过        rewrite ^/your_app/(. *) $/your_app/ index.php?$1;}     }

Nginx on rewrite recommended to use the official and I recommend the Try_files method;)

Location/{    try_files $uri $uri//index.php$uri? $args;}

See why you use Try_files instead of using if to judge

Portal 1:http://wiki.nginx.org/httpcoremodule# ...
Portal 2:http://wiki.nginx.org/ifisevil

Turn on route matching, then open rewrite mode in Apache

  • 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.