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

888u

Last update at :2024-06-19,Edit by888u

Snails previously shared an article called "LNMP Tutorial Series 5: How to Set up 301 Redirect". We can easily set up a 301 redirect in the nginx environment. Generally speaking, the 301 jump we use is the jump between WWW and non-WWW domain names. In jargon, the weights must be normalized. For those of us using the Apache environment, it is actually simpler than nginx, because we only need to have the .htaccess file in the root directory of the website.

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

First, jump to a domain name without www with www

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

Second, jump to the www domain name without www

RewriteEngine OnRewriteCond %{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 it. Just record it like a snail and copy it directly next time.

Newly added: If the website is moved, all old domain names will be redirected to the new site with 301:

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

Recommended site searches: free stable space, free virtual space, domain name registration, anti-complaint server, foreign virtual space, use IP to check address, domain name valuation query, foreign server vps, overseas server rental price, virtual space purchase,

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

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