Level 6
Added
if ($host = domaingo.com) {
return 301 https://domain.com$request_uri;
}
in the second server block dealing with port 443 and that solved the issue.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
We would like domaingo.com excluding its subdomains to go to domain.com on the same Laravel Forge Digital Ocean droplet
We can add forge redirect 302 to main domain.com in Laravel Forge, but we worry we overwrite the general http to https redirect. Here is the config we have now generated by Forge with some additions:
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/domain.com/before/*;
server {
listen 80;
listen [::]:80;
server_name *.domaingo.com;
# Redirect to HTTPS version
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name .domaingo.com;
server_tokens off;
root /home/forge/domain.com/current/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/domaingo.com/1012559/server.crt;
ssl_certificate_key /etc/nginx/ssl/domaingo.com/1012559/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDH-ECDSA-AES128-SHA:
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
# https://www.laravel-enlightn.com/docs/security/hsts-header-analyzer.html
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/domain.com/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/domaingo.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name .domain.com;
root /home/forge/domain.com/current/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/domaingo.com/1012559/server.crt;
ssl_certificate_key /etc/nginx/ssl/domaingo.com/1012559/server.key;
ssl_protocols TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "application/json";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/domain.com/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/domain.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
#Bugsnag crossorigin
location ~ \.js {
add_header Access-Control-Allow-Origin "*";
}
#modulesettings remove cache
location /modulesettings/ {
expires 0;
}
}
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/domain.com/after/*;
How can we redirect only main domain domaingo.com to domain.com and keep all subdomains under domaingo.com loading as they are?
Added
if ($host = domaingo.com) {
return 301 https://domain.com$request_uri;
}
in the second server block dealing with port 443 and that solved the issue.
Please or to participate in this conversation.