Apache 301 will turn the domain name with www to the domain without www

  
                  

I haven't paid much attention to the jump problem of this website. By chance, a friend said that my website www.45it.com and 45it.com didn't do 301. This is really the case. Although the main domain name of the website is set to www.45it.com, when 45it.com is accessed, it will not jump. So add the following code in .htaccess, perfect for apache to transfer other domain names (such as domain names without www) to the domain name with www, record it for sharing. The code is as follows:

Environment:

System Windows Apache 2.2

The code we want to implement is as follows
Code is as follows Copy code

RewriteEngine on RewriteCond %{HTTP_HOST} 45it.com [NC] RewriteRule ^(.*)$ http://www.45it.com/$1 [L,R=301]

If you don't have mod_rewrite, you can set mod_alias:
Copy the code

RedirectMatch 301 ^(.*)$ http://www.45it.com

Friendly Tips

Load Rewrite Module:

In the conf directory Found in httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so

In this sentence, remove the preceding comment symbol “#”, or add this sentence.

Copyright © Windows knowledge All Rights Reserved