Common and practical methods for domain name 301 redirection in nginx and apache environments

888u

Last update at :2023-12-27,Edit by888u

This site published an article a long time ago "Baidu Answers Summary of Frequently Asked Questions about 301 Jumps". The answers in it are all from Du Niang's official staff. It can be seen that 301 redirection is still quite important. , especially if you change the domain name, you must use it. Now let’s summarize the common and practical methods of domain name 301 redirection in nginx and apache environments. They have also been used by this site before. It is impossible to know who is the original author. Anyway, it can be used.

1. nginx higher version support:

server {
  server_name this site.com;
  return 301 https://www.thissite.com$request_uri;
}

2. Rewriting method nginx universal support:

server {
    server_name this site.com;
    rewrite ^(.*) https://www.thissite.com$1 permanent;
}

3. Judgment rewriting method:

if ($host != 'www.thissite.com'){
rewrite ^/(.*)$ https://www.thissite.com/$1 permanent;
}

Apache domain name 301 redirect .htaccess
Method 1:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://www.thissite.com/$1 [R=301,L]

Method 2:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^this site.com/ [NC]
RewriteRule ^(.*)$ https://www.thissite.com/$1 [L,R=301]

At any time, you must be a thoughtful person, record the answers you find to questions at any time, and share them at any time, which can not only facilitate yourself but also facilitate others. You may not need 301 orientation now, but you may encounter it in the future. I suggest friends who like it to bookmark the site. Thank you!

Recommended site searches: IP address search, US PHP space, virtual host application, Korean proxy server, website domain name query, vps host, free server website US host forum, telecom ip agent, windows virtual host,

Common and practical methods for domain name 301 redirection in nginx and apache environments

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码