---
title: "Nginx rewrite permanent"
author: "sw1982"
date: "2014-03-19T16:43:45Z"
tags: ["nginx"]
categories: ["Web前端"]
slug: "nginx-rewrite-permanent"
draft: false
lastmod: "2014-03-19T16:43:45Z"
id: 2033627
url: "https://sw1982.iteye.com/blog/2033627"
---

fpm之后，尝试兼容url错误的一段redirect失效。具体如下：

```
rewrite ^/hoomic-plugin/(.*)$ /$1 permanent;

目的是使得下面网站都可以访问：
http://plugin.abc.com/index.php/info
http://plugin.abc.com/hoomic-plugin/index.php/info
```

 

非常不幸的是由LAMP迁到nginx 的ftpm中后，执行不成功。

1.打开nginx debug log,发现redirect没问题，而是request uri不同。

```
server {
       listen 80;
       server_name plugin.abc.com;
       root /var/hoomic-plugin;
       index index.html index.php;
       error_log    /var/log/nginx/plugin.error.log debug ;
       rewrite_log on;
```

   
![](http://dl2.iteye.com/upload/attachment/0095/0884/7aa592c7-76ec-3a38-9b14-6e8735cf840f.png)  
 

于是改用 permnent, 301强制重定向到正确的url上面。

```
rewrite ^/hoomic-plugin/(.*)$ /$1 permanent;
```

 

 

last：

   重新将rewrite后的地址在server标签中执行

break：

    将rewrite后的地址在当前location标签中执行

 

```
rewrite ^(.*)/index.html$ $1 permanent;
```

 

http://wiki.nginx.org/Codeigniter