Home > nginx > Nginx redirect folder to subdomain

Nginx redirect folder to subdomain

June 5Hits:2

I'm trying to configure a redirect on Nginx from a folder to a subdomain. I've tried already Nginx redirect: folder to external domain and Nginx rewrite rule (subdirectory to subdomain) and nginx: redirect subfolder to subdomain. Nothing works.

The problem, are simple. I have a Apache configured with this line:

RedirectPermanent /asd http://asd.domain.com/

Now, I'm trying to replicate this on a Nginx. Every configuration I've tried, have the same problem:

If I go to http://www.domain.com/asd/, they redirect me to http://asd.domain.com/asd/.

If I go to http://www.domain.com/asd/index, they redirect to http://asd.domain.com/index.

I need to delete the sub-folder in all cases, for me, the first one are incorrect. How can I configure nginx for in first case, go to http://asd.domain.com/?

The rules are applied after root parameter. The config are:

server {   listen --   server_name --   root --   <> INSERT RULE HERE   access_log --   error_log --   include - (A file with php configurations). } 

Some examples of tried rules:

rewrite ^/asd/(.*) http://asd.domain.com/$1 permanent;

rewrite ^/asd(.*) http://asd.domain.com/$1 permanent;

rewrite ^/asd(.*) http://asd.domain.com$1 permanent;

location ^~ /asd/ { rewrite ^/asd/(.*) http://asd.domain.com/$1 permanent; }

location ^~ /asd/ { rewrite ^/asd(.*) http://asd.domain.com/$1 permanent; }

location ^~ /asd/ { rewrite ^/asd(.*) http://asd.domain.com$1 permanent; }

Also, location variation with "location ~ ^/asd/(.)" or "location ~ ^/asd(.)"



I think you were close with rewrite ^/asd/(.*) http://asd.domain.com/$1 permanent;

Per the documentation:

If a replacement string includes the new request arguments, the previous request arguments are appended after them. If this is undesired, putting a question mark at the end of a replacement string avoids having them appended

But you might need to add a ?, and just for good practice that ending $ as such:

rewrite ^/asd/(.*)$ http://asd.domain.com/$1? permanent;

Related Articles

  • Nginx redirect folder to subdomainJune 5

    I'm trying to configure a redirect on Nginx from a folder to a subdomain. I've tried already Nginx redirect: folder to external domain and Nginx rewrite rule (subdirectory to subdomain) and nginx: redirect subfolder to subdomain. Nothing works. The p

  • Nginx redirect route to subdomainJanuary 7

    I'm trying to redirect 15 different routes with Nginx from folders to subdomains (I already read some threads about this). I'm very confused because this redirect is working: rewrite ^/admin(.*) $scheme://admin.example.com/$1 301; while this one is n

  • Apache Redirect folder to subdomainSeptember 8

    A client had an application at www.domain.com/dir. They have now set up a subdomain at dir.domain.com. The subdomain references the files stored at www.domain.com/dir. They'd now like people accessing www.domain.com/dir to be redirected to dir.domain

  • nginx redirect to a subdomain even without trailing slashesMarch 10

    I just installed and partially configured nginx on a dedicated server of mine. But I've got some trouble understanding the regexp. I would like to make nginx redirect www.mydomain.com/forum/ AND www.mydomain.com/forum (note the missing trailing slash

  • nginx: redirect subfolder to subdomainMay 15

    I'm trying to redirect a subfolder to a subdomain in nginx. I want http://example.com/~meow/ to be redirected to http://meow.example.com/. I tried the following: location ~ ^/\~meow/(.*)$ { rewrite ^(.*)$ http://meow.example.com$1 permanent; } But it

  • nginx: redirecting only 'www' subdomain to main domain?April 19

    Update: April 20th 2013, Still no solution found, please help Looking at my nginx config, the only like that could be the culprit is this: server { listen 80; listen [::]:80 ipv6only=on default_server; rewrite ^(.*) https://$host$1 permanent; } Liter

  • nginx redirect localhost and subdomainJuly 31

    I am trying to put a development server in place on the same server as the production server. The two will run on different ports, and one will be accessible via prod.example.com and the other via dev.example.com. There is a DNS A record in place alr

  • Wordpress redirect folder to subdomainMarch 19

    I have recently redone my website in wordpress and moved it to a different server. I need www.example.com/releases to point to another IP. I have set releases.example.com to point to this IP. So I'd now like when someone browses to www.example.com/re

  • Nginx redirect: folder to external domainJune 10

    I'm trying to redirect domain1.com/blog/$ to domain2.com/$. How do I edit this to strip the /blog from the redirect? location /blog { rewrite ^/(.*) http://domain2.com/$1 break; } It now redirects domain1.com/blog/blabla to domain2.com/blog/blabla (s

  • nginx redirect to another domain not forgetting about the subdomainsOctober 7

    this is rather a quick one: How do I redirect to another domain and still forward the subdomain? Example: http://foo.domainone.com/bar.php -> http://foo.domaintwo.com/bar.php Thanks in advance! --------------Solutions------------- Something along the

  • Nginx redirect or rewrite with folderFebruary 20

    I have a virtual machine with an apache which serves a web application at https://my.ip.address/web/index.hml (internal). At the router/firewall is a nginx running which works as an reverse proxy with an external address: https://subdomain.example.co

  • Nginx: Redirect all traffic to Coming Soon page except own IPJune 11

    I have a folder called "coming-soon" that I would like to redirect all traffic to when the site is down for maintenance. Currently, this is what I did: ----- START ----- location / { allow 123.456.789; deny all; page_error 403 coming-soon/index.

  • Apache Alias subdomain/folder to folder above subdomainSeptember 20

    What I want to do is to create an alias at http://subdomain.example.com/login that points to /usr/.....etc/htdocs/example/login so that anytime someone is redirected to http://subdomain.example.com/login where they will end up is at ...../example/log

  • nginx redirects requests from apache proxy to real server addressApril 9

    Description: [server 1] <-|-> [server 2] [Apache] <-|-> [nginx <--> gunicorn <--> django] Apache is running on a server 1 which silently redirects just one subdomain to server 2. For some reason nginx returns 301 moved permanently

  • nginx: Redirect all requests to a proxy, but not these three specific URLsAugust 4

    nginx can be tricky sometimes: I want to redirect all incoming requests for www.sub.domain.com/* to www.other.domain.com/* use a proxy so users still see the original www.sub.domain.com when browsing the site add an exception for specific URLs (all t

  • nginx: Redirecting without changing the address line in the browserNovember 15

    I have a support system installed with a different hoster and want the address from my web application to contain a link to that support system. However, the domain name I registered together with this support system is completely unrelated to the na

  • cannot write to nginx www folderApril 29

    I've recently installed nginx on my dev machine with Ubuntu 12.04. I am currently logged in as myuser and after installing nginx I setup the following file permissions (nginx www folder was owned by root so I wanted to change that so I can edit files

  • apache + nginx(for only one subdomain)October 11

    I have a nice little Server with Ubuntu 12.04 LTS with Apache controlled by plesk. Now I've installed nginx for my Gitlab subdomain. But now nginx wants to control all. How can I configure the nginx server to provide only one subdomain: git.example.c

  • Roaming Profile to act as a redirected folder? Dropbox in roaming profile is also causing slow login/logouNovember 26

    As title, what I'm wondering to know is .. if the roaming profile with Windows 2008 R2 Server (I'm talking about V2 profile - Windows7/Windows8) can work as a redirected folder (it can be done with the Desktop, Contacts, Download, AppData, My Documen

  • wordpress multisite domain mapping redirects to original subdomainDecember 5

    This week I installed Wordpress 3.4.2 (Linux Centos + Apache2) and configured the network option using subdomains. Then I installed the MU Domain Mapping plugin, so I would be able to use it with domain names instead of subdomains. This works for one

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.394 s.