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 ?; |