Score:0

"rewrite" structure for subdomain on Nginx

cn flag

I want to do a custom rewrite for the subdomain on ISPconfig. When I add the code below for this, the subdomain is redirected to the main domain.

Sample #1:

server {
  ...
     if ($http_host = "panel.example.com") {
         rewrite ^(?!/(_SubDomains/Panel|stats|\.well-known/acme-challenge))/(.*)$ /_SubDomains/Panel/$2 last;
         rewrite ^/(.*)/(.*)$ /index.php?cmd=$1&scd=$2? last;
      }
  ...
 }

If I do as in example two, Nginx server does not work.

Sample #2:

server {
...
     if ($http_host = "panel.example.com") {
         rewrite ^(?!/(_SubDomains/Panel|stats|\.well-known/acme-challenge))/(.*)$ /_SubDomains/Panel/$2 last;
         location ~ \.php$ {
                 rewrite ^/(.*)/(.*)$ /index.php?cmd=$1&scd=$2? last;
         }
     }
...
}

I was using in Apache server like this:

<IfModule mod_rewrite.c>
    SetEnv HTTP_MOD_REWRITE On
        RewriteEngine on
        RewriteBase /
        RewriteCond %{REQUEST_URI} !\.php$ [NC]
        RewriteCond %{REQUEST_URI} [^/]$
        RewriteRule ^(.*)$ $1.php [L]
        RewriteCond %{REQUEST_FILENAME} -d [OR]
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -l
        RewriteCond %{REQUEST_URI} !.(css|gif|ico|jpg|js|png|swf|txt)$
        RewriteRule ^ - [L]
        RewriteRule ^([^/]+)/([^/]+)?$ index.php?cmd=$1&scd=$2 [L,QSA]
        RewriteRule ^([^/]+)/?$ index.php?cmd=$1 [L,QSA]
</IfModule>

Without rewrite link: https://panel.example.com/index.php?cmd=abc&scd=xyz

With Rewrite: https://panel.example.com/abc?scd=xyz

How can I use it on Nginx PHP-FPM server like I use it on Apache server in subdomain?

kz flag
What exactly are you trying to do?
Emre6 avatar
cn flag
Hi, I've updated the question to explain better. @MrWhite
djdomi avatar
za flag
you want server_name domain.bla.tld instead of if, if is bad for nginx
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.