Nginx rewrite Pseudo-static configuration in the DiliCMS framework

Source: Internet
Author: User


Example

The code is as follows: Copy code

Server {
Listen 80;
Root/path/to/dilicms /;
Index. php;
Server_name www.111cn.net;

Location ~ ^ (/(Application | system | services | shared | admin/backup | admin/config | admin/controllers | admin/core | amdin/errors | admin/hooks | admin/language)) /{
Deny all;
    }

Location /{

If ($ request_uri ~ * Index /? $)
        {
Rewrite ^/(. *)/index /? $/$1 permanent;
        }

If (! -D $ request_filename)
        {
Rewrite ^/(. +)/$1 permanent;
        }

Set $ admin '';

If ($ request_uri ~ * ^/Admin /){
Set $ admin;
        }

If ($ request_uri ~ * ^/Install /){
Set $ admin B;
        }

If (! -E $ request_filename ){
Set $ admin "X $ {admin }";
        }

If ($ admin = XA ){
Rewrite ^/admin/(. *) $/admin/index. php? /$1 last;
Break;
        }

If ($ admin = XB ){
Rewrite ^/install/public/(. *) $/install/public/index. php? /$1 last;
        }

If ($ admin = X ){
Rewrite ^/(. *) $/index. php? /$1 last;
Break;
        }

    }


Location ~ . Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/path/to/dilicms $ fastcgi_script_name;
Include fastcgi_params;
    }

Location ~ /. Ht {
Deny all;
    }
}

The following are some examples of nginx Rewrite.


Used to use the. htaccess file only in Apache to configure all the information.

The code is as follows: Copy code

RewriteCond % {HTTP_HOST} example.org
RewriteRule (. *) http://www.example.org $1

The translation is as follows:

The code is as follows: Copy code

Server {
Listen 80;
Server_name www.example.org example.org;
If ($ http_host = example.org ){
Rewrite (. *) http://www.example.org $1;
        }
...
    }

This is wrong, complex, and inefficient. The correct method is to define a separate server for example.org:

The code is as follows: Copy code

Server {
Listen 80;
Server_name example.org;
Return 301 http://www.example.org $ request_uri;
    }

Server {
Listen 80;
Server_name www.example.org;
...
    }

Before Version 0.9.1 (inclusive), you can implement redirection as follows:

The code is as follows: Copy code

Rewrite ^ http://www.example.org $ request_uri ?;

Another example is to process the opposite logic: neither example.com nor www.example.com:

The code is as follows: Copy code

RewriteCond % {HTTP_HOST }! Example.com
RewriteCond % {HTTP_HOST }! Www.example.com
RewriteRule (. *) http://www.example.com $1

You should define example.com, www.example.com and other sites separately as follows:

The code is as follows: Copy code

Server {
Listen 80;
Server_name example.com www.example.com;
...
    }

Server {
Listen 80 default_server;
Server_name _;
Return 301 http://example.com $ request_uri;
    }

Before Version 0.9.1 (inclusive), you can implement redirection as follows:

The code is as follows: Copy code

Rewrite ^ http://example.com $ request_uri ?;

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.