The key points of 301 have always been exposed to many SEOers. I believe that when doing 301, many websites just go online to find the relevant rules and then change them. It can be said that many people do not know the meaning of the rules. Today, I use "Apache" I will share with you "Server" and "IIS Server" as examples. Please forgive me if there is anything wrong.
If the website server is Apache, add the following rules at the beginning of the .htaccess file (if you do not have permission to modify it, please contact the service provider for assistance in modifying it):
RewriteCond %{http_host} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
{HTTP_HOST} is a server variable
^ is the starting position of the matched input string.
$ is the end position of the matched input string.
R=301 means to perform permanent redirection. Since R also means 302, R=301 is emphasized here.
L means end of rule
One of the most commonly used regular expressions is (.*). It contains two elements: one is "dot", which represents any character; the other is "star", which represents all previous characters. So (.*) will match all characters of {REQUEST_URI}. {REQUEST_URI} is all the query characters excluding the domain name and the "?" symbol in the URL, and it is also the character that Apache rewriting technology tries to match.
[NC] tells the Apache server to ignore case in the regular expression. It is often used on the {HTTP_HOST} server parameter because domain names are not case-sensitive;
If the website server is IIS, use the ISAPI_Rewrite component and add the following rules at the beginning of the httpd.ini file:
RewriteCond Host: ^domain.com$
RewriteRule (.*) http://www.domain.com$1 [R,I]
^ is the starting position of the matched input string.
$ is the end position of the matched input string.
(.*) will match all characters of {REQUEST_URI}.
I forces specified character matching regardless of case. This FLAG affects the RewriteRule directive and the corresponding RewriteCond directive.
R forces the server to issue a redirection instruction to the client and respond immediately, providing the new address of the destination URL. The redirection rule is often the last rule.
marks the next character as a special character, or a literal character, or a backreference, or an octal escape character.
Note: The above code domain.com is an example. If the description is incorrect, please point it out. This article was written by the webmaster of Hangzhou Extramarital Affairs Investigation Company http://www.hydc007.com . Please keep it for reprinting.
Thanks to Hangzhou Private Detective for your contribution