# 如何在 nginx 中实现 htaccess 中的操作？

**URL:** <https://meta.discourse.org/t/how-do-i-do-what-i-did-in-htaccess-in-nginx/80772>\
**Category:** Self-hosting\
**Created:** [2018 年2 月 16 日 19:55 UTC](https://meta.discourse.org/t/how-do-i-do-what-i-did-in-htaccess-in-nginx/80772 "2018-02-16T19:55:48Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

作者： ![MostHated](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MostHated](https://meta.discourse.org/u/MostHated)\
发布日期： [2018 年2 月 16 日 20:00 UTC](https://meta.discourse.org/t/how-do-i-do-what-i-did-in-htaccess-in-nginx/80772/3 "2018-02-16T20:00:52Z")

</div>

I am already running it externally, I just wasnt sure how to go about that part. Thanks! I will give that a go now.

–  
There is more to it isn’t there? Doesn’t a variable have to go at the end of the path based on the subdomain? It will not always be the same. Here is how I had it before.

```
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} \.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/forum/t/%1$1 [L,NC,QSA]

```

Ah, I found this! [htaccess to nginx converter](https://winginx.com/en/htaccess)  
A htaccess to nginx converter, that is convenient, lol.

If I am already using proxypass and such, do I just put this in location along with all that? or does it have to go before or after it or something?

```
  if ($http_host !~ "^www\."){
    rewrite ^(.*)$ http://domain.com/forum/c/%1$1 redirect;
  }

```

Right now it looks like this

```
location /forum {
    proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
    proxy_set_header Host $http_host;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
}
fastcgi_read_timeout 60;

```

}

I just tested it out some more, it turns in to a loopy mess, lol.

---

_[View the full topic](https://meta.discourse.org/t/how-do-i-do-what-i-did-in-htaccess-in-nginx/80772)._
