.htaccess到nginx conf

时间:2014-11-17 14:54:16

标签: .htaccess nginx

我有.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 working] [domain.tld working] [找不到文件。]

我的应用程序结构是

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

1 个答案:

答案 0 :(得分:2)

Sepcifiy索引文件: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;
    }

}