Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


How can I do subdomain-specific rewrite?

What I have tried:

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?
Posted
Updated 25-Dec-21 1:04am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900