Focus on cloud service provider activities
Notes on website operation and maintenance

Apache environment. htaccess pseudo static 301 jump (www and without www)

Lao Zuo shared an article before“ LNMP Series Tutorial 5: How to Set 301 Redirection "In this article, we can easily set the 301 Jump In general, we use 301 Jump It refers to the jump between WWW and domain names without WWW. In jargon, it means that the weight should be unified. It is actually simpler for us to use Apache environment than nginx, because we only need to have it in the root directory of the website htaccess File.

If our website, such as wordpress root directory, has htaccess After the file, we only need to add the following code in the file to realize the jump between www and www without www, and transfer the weight reasonably.

First, jump from the domain name with www to the domain name without www

RewriteEngine On
RewriteCond %{HTTP_HOST} !^ laozuo.org$ [NC] RewriteRule ^(.*)$ http://laozuo.org/ $1 [L,R=301]

Second, jump to the www domain name without www

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

Generally, the above two methods are used. It doesn't matter if you can't remember them. Just like Lao Zuo, you should record them. Next time, you should copy them directly.

Newly added If the website moves, all old domains 301 will jump to the new site:

RewriteEngine on
RewriteRule ^(.*)$ https://www.laozuo.org/ $1 [R=301,L]

Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Apache environment. htaccess pseudo static 301 jump (www and without www)


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge