繁体   English   中英

.htaccess到nginx conf

[英].htaccess to nginx conf

我有这个.htaccess重写规则

AddDefaultCharset UTF-8
RewriteEngine On
RewriteRule ^(administrator) - [L]
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

和Nginx版本重写规则

charset utf-8;
rewrite ^/$ /public/ last;
rewrite /(.*) /public/$1 last;

location ~* ^/(administrator) {
    break;
}

当前的.htaccess将所有请求重定向到/ public文件夹(/ administrator请求除外)。 使用nginx规则,[domain.tld / rss.php 不起作用 ] [domain.tld / administrator起作用] [domain.tld起作用] [找不到文件。]

我的应用程序结构是

.
..
index.php [require public/index.php] 
administrator/index.php
public/index.php
public/rss.php
public/css
public/js

分隔一个索引文件: index index.php

顺便说一句,您应该将重写放在适当的位置,以避免对每个请求进行测试。 可读性/可维护性也更好。

server {

    server_name domain.tld;
    root /path/to/root;

    location ~ /(administrator|public) {
        index index.php;
        ...
    } 

    location / {
        rewrite ^/$ /public/ last;
        rewrite ^(.*)$ /public/$1 last;
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM