![尝试根据子域名进行重定向](https://linux22.com/image/1590156/%E5%B0%9D%E8%AF%95%E6%A0%B9%E6%8D%AE%E5%AD%90%E5%9F%9F%E5%90%8D%E8%BF%9B%E8%A1%8C%E9%87%8D%E5%AE%9A%E5%90%91.png)
我有两个文件夹:
- 文件夹 A 中是托管具有域名的页面的站点
www.mydomain
。 - 文件
mydomain.com
夹 B 中是带有域名的站点demo.mydomain.com
我该怎么做?我尝试了以下方法,但没有效果。
server {
listen 80;
server_name example.com;
rewrite ^/(.*) http://www.example.com/$1 permanent;
}
server {
listen 80;
server_name www.example.com example.com;
root /var/www/html/folderA;
}
server {
listen 80;
server_name ~^(.*)\.example\.com$;
# Sets the correct root
root /var/www/html/folderB;
}
答案1
非常感谢你的帮助,我终于解决了这个问题
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html/folderA;
index index.php index.html;
rewrite ^/folderB/(.*)$ http://demo.example.com/$1? permanent;
location /images {
autoindex on;
}
}
server {
listen 80;
server_name demo.example.com;
root /var/www/html/folderB;
index index.php index.html;
location /images {
autoindex on;
}
}