I'm configuring Nginx to handle redirects for a domain, but I'm encountering an issue with preserving the URL for a specific path. Here's my scenario:
I have a domain, let's say landing.immancrze.us, and I want all requests to this domain to be redirected to app.immancrze.us, except for requests to the path landing.immancrze.us/potential-ownership. For the latter, I want to serve the content without redirection and ensure that the URL remains unchanged.
for example:
Requests to
landing.immancrze.uswill be redirected toapp.immancrze.us.Requests to
landing.immancrze.us/potential-ownershipwill be served directly without redirection and the URL in the browser will remain unchanged likehttp://landing.immancrze.us/potential-ownership. but it will getting changed tohttp://app.immancrze.us/potential-ownership
Here's the Nginx configuration I've tried:
server {
listen 80;
server_name landing.immancrze.us;
# Redirect root path to app.immancrze.us
location = / {
return 301 http://app.immancrze.us$request_uri;
}
# Serve content for /potential-ownership without redirection
location = /potential-ownership {
root /usr/share/nginx/html/;
index index.html;
try_files $uri $uri/ /index.html;
}
# Serve JavaScript files with custom headers
location ~ \.js$ {
sendfile off;
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
#proxy_no_cache 1;
#proxy_cache_bypass 1;
}
# Handle all other requests by redirecting to app.complycta.us
location / {
return 301 http://app.immancrze.us$request_uri;
}
}
/usr/share/nginx/html/potential-ownershipa directory containingindex.html?index.htmlfrom/usr/share/nginx/html/you need to usetry_files /index.html =404;index.htmlalso requires resource files (JS, CSS, JPEG) you may have a problem. You will need to identify the URLs for those resource files and add exceptions for those too.