0

I've been using Appserv for a while and moved to Nginx for now. When I was running my website under Appache I had this configuration in the .htaccess file in order to link the subdomain to the subdirectory.

#Redirect API subdomain to API folder
RewriteCond %{HTTP_HOST} ^api\.domain\.com$
RewriteCond %{REQUEST_URI} !^/request/
RewriteRule (.*) /request/$1

I tried to add this configuration to the nginx.conf file to do the same:

location ^~ /request/ {
    rewrite ^/request/(.*) http://api.example.com/$1 permanent;
}

It seems like it doesn't work since I'm being redirected to the main domain URL. How do I manage to do that in Nginx ?

Avi
  • 101

1 Answers1

-1

there are a few different ways of doing it, but my preference for being easy to read:

    location / {
        if ($http_host = api.domain.com) {
            try_files /request$uri =404;
        }
    }

nginx documentation converting Apache rewrite rules.

h0tw1r3
  • 2,746
  • 18
  • 17