我想rewrite
在 ISPconfig 上对子域名进行自定义。当我为此添加以下代码时,子域名将重定向到主域名。
样本#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;
}
...
}
如果我按照示例二进行操作,Nginx 服务器将无法工作。
示例#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;
}
}
...
}
我在 Apache 服务器中使用如下方式:
<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>
不带重写链接:https://panel.example.com/index.php?cmd=abc&scd=xyz
重写后:https://panel.example.com/abc?scd=xyz
如何在 Nginx PHP-FPM 服务器上使用它,就像在子域中的 Apache 服务器上使用它一样?