Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to redirect virtual host 301

Shulou Source: shulou.com Published: 2022-06-02 01:48:25 09月21日 Update

How to redirect virtual host 301? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

The virtual host 301 is redirected, which is divided into Linux virtual host and Windows virtual host. 301 is configured differently for different operating systems.

301 redirection is a very important "automatic steering" technology. For example, when we visit west.cn, we see https://www.west.cn/; when we visit www.west.cn, we also visit the https://www.west.cn/ page. This is to do 301 redirection, unify different domain name forms into one URL, can achieve URL standardization, and leave a good impression on users and search engines.

1. How to redirect the virtual host 301 of Linux system

Linux virtual host, general pseudo-static rules are put into .htaccess file:

RewriteEngine OnRewriteCond% {HTTP:From-Https}! ^ on$ [NC] RewriteCond% {HTTP_HOST} ^ (www.)? xxx.com$ [NC] RewriteRule ^ (. *) $https://www.xxx.com/$1 [Rene301 Magi L]

# Jump xxx.com and www.xxx.com to https://www.xxx.com, to prevent the apache substation from inheriting the parent directory. .htaccess is affected. Delete the comments by yourself and do not need to put the htaccess file.

2. How to redirect the virtual host 301 of Windows system

Windows virtual host, generally pseudo-static rules are put into the web.config file.

# www.xxx.com should be modified to your own domain name. Delete the comments by yourself and do not need to put them in the web.config file.

Of course, in addition to the above configuration file, we can also use code directly:

Windows virtual host, ASP language:

Response.Status= "301 Moved Permanently" Response.AddHeader "Location", "https://www.xxx.com"Response.End"

Linux virtual host, PHP language:

Header ("HTTP/1.1 301 Moved Permanently"); header ("Location: https://www.xxx.com");exit();"

Description: just add the code to the relevant page. It is usually put in the header file.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Host virtual host file different system code domain name method comment rule language static page help configuration clear important operating system superior content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info MariaDB Shulou Technology Huawei