【问题标题】:.htaccess to nginx conf.htaccess 到 nginx 配置文件
【发布时间】:2015-01-14 12:33:25
【问题描述】:

我有这个 .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 not working] [domain.tld/administrator working] [domain.tld working] [File not found.]

我的应用结构是

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

【问题讨论】:

    标签: .htaccess nginx


    【解决方案1】:

    选择一个索引文件: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;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 2018-02-24
      • 2019-04-09
      • 2016-07-15
      相关资源
      最近更新 更多