[英]Want to redirect old domain to new domain using nginx but not working
我已經為前端和后端代碼設置了兩個Sub域。 如果用戶點擊舊域名,我想重定向新域名。 但是我收到錯誤消息-“ 414請求URI太大”。 我正在使用Nginx服務器作為后端代碼。
server {
root /var/www/html/frontendCode/dist;
index index.php index.html index.htm;
server_name dev.olddomain.com;
location / {
try_files $uri $uri/ /index.html;
}
rewrite ^ $scheme://dev.newdomain.com$request_uri permanent;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name devapi.olddomain.com;
root /var/www/html/apiBackendCode/public;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
rewrite ^ $scheme://devapi.newdomain.com$request_uri permanent;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri =404;
}
}
您可以使用以下方法進行重定向:
server {
listen 80;
server_name dev.domain1.com;
rewrite ^/(.*) https://dev.domain2.com/$1 permanent;
}
嘗試這個
server {
server_name .mydomain.com;
rewrite ^ http://www.adifferentdomain.com$request_uri? permanent;
}
您可以嘗試像這樣的重定向。
return 301 http://dev.newdomain.com$request_uri;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.