Automatically jump to the second-level domain name without the www top-level domain name: the root domain name 301 redirects www

如果WordPressWhen the website contains 2 domain names (with www domain name and without www domain name) can be accessed, it is very unfavorableSEOThe concentration of weights, and the subsequent search engine optimization indexing.

How can we solve it?

This requires a permanent 301 redirection of domains without www to domains with www.

Automatically jump to the second-level domain name without the www top-level domain name: the root domain name 301 redirects www

Website root domain name 301 redirect www domain name benefits

The advantage is that it can increase the authority of the domain name.

A 301 redirect is actually a transfer of domain authority.

For example, when chenweiliang.com redirect to www.chenweiliang.com when in fact the chenweiliang.com The weight of is transferred to www.chenweiliang.com , thereby increasing the www.chenweiliang.com 's domain name.

  • Improve search engine optimization performance;
  • Conducive to the transmission of web page weights;
  • Optimize web page indexing.

when we openE-commercewebsite, two identical pages appear.

  • At this time, search engine spiders will repeatedly crawl.
  • Duplicate pages can lead to misjudgments by search engines.
  • At this time, you need to use 301 redirection to process and optimize web page inclusion;

Better user experience:Without duplicate pages, users will remember our website better, improve the memory of the website, and get a better user experience.

Disadvantages of website without www secondary domain name

  • A small number of users may not be able toUFO.org is identified as a web address;
  • A small number of users will only recognize second-level domains with the www URL pattern www.etufo.org

How do top level domains 301 redirect to www?

The following is based onLinuxServer-implemented solutions.

step 1: New .htaccess file

Usually our computer uses the Windows operating system, and we cannot directly create a new .htaccess file.

You must create a new htaccess.txt file first, and how to change the name will be described later.

Step 2: Copy the following code into the txt document

RewriteEngine On
RewriteCond %{http_host} ^chenweiliang.com$ [NC]
RewriteRule ^(.*)$ http://www.chenweiliang.com/$1 [R=301,L]
  • "RewriteEngine On", turn on the Rewrite Rule switch;
  • "RewriteCond" refers to the rewrite condition.
  • The following string is matched by a regular expression, and the matched string starts with ^ and ends with $.
  • Here %{http_host} is to get the current hostname.The condition is "When the hostname is chenweiliang.com", the following rewrite rules will be executed.
  • "[NC]" means case insensitive;
  • "RewriteRule", defines the rewrite rule.Meaning here: jump to the URL" http://www.chenweiliang.com/ "Access Request chenweiliang.com later part.
  • [R=301] means rewriting as 301 redirect/jump ([R] single-finger jump, the same meaning as [R=302]), [L] means the last matching rule.

Step 3: Upload the htaccess.txt file and modify the name

Use the FTP tool to upload the htaccess.txt file to the root directory of the website and rename it to ".htaccess", notice the dot in front.

  • If the file already exists, copy the code into it.
  • This way, when you visit a domain name without www, it will automatically redirect to the domain name with www.
  • Through the above method, the domain name without www can be automatically redirected to the domain name with www.

Note: After modifying here, you may find that the file is missing.

This is because".htaccess” files are considered hidden and will not be displayed.

You can open the FTP tool, here XFTPsoftwareFor example, in [Tools] → [Options] ▼

This is because ".htaccess" files are considered hidden and will not be displayed.You can open the FTP tool, here takes XFTP software as an example, in [Tools] → [Options] sheet 2

【General】→check【Show hidden files】▼

[General] option → check [Show hidden files] 3rd sheet

 

Here we share the general rules of redirecting a domain name with www to a domain name without www, and a domain name without www to a domain name with www.

Rules for redirecting domains with www to domains without www

301 redirect TLD with www to root domain rules▼

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

The following top-level domain name with www 301 redirects to the root domain name rule, which can be copied directly (no need to modify the domain name in the rule) ▼

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

TLDs without www jump to domains with www rules

TLDs without www jump to domain rules with www ▼

RewriteEngine On
RewriteCond %{http_host} ^chenweiliang.com$ [NC]
RewriteRule ^(.*)$ http://www.chenweiliang.com/$1 [R=301,L]

The following top-level domain names without www jump to the domain name rules with www, which can be copied directly (no need to modify the domain name in the rules) ▼

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

301 redirect rule location problem

Under pseudo-static rules, when placing redirect jump rules, you will usually encounter http cannot redirect to https The problem.

Initially we copied the redirect code into .htaccess and it will appear in the following cases ▼

Redirection rule [L] in the 4th sheet above

  • [L] indicates that the current rule is the last rule, stop analyzing the following rewrite rules.
  • So when accessing the redirected article page, [L] stops the following rule, so the redirection rule doesn't work.

When visiting the http homepage, we want to trigger a URL redirection, skip the pseudo-static rule to execute the redirection jump rule, so that it can be achievedSite-wide http redirect to https .

Don't put https redirect rules in [L] Below the rules, put [L] above the rules ▼

Pseudo-static SSL redirection rules [L] in the 5th sheet below

Is it necessary to redirect www for the main domain name of the website?

If you use directly like chenweiliang.com Such a top-level domain name is used as your blog domain name, so using a subdomain name as a picture bed cannot achieve Cookie-free.

  • because the top-level domain chenweiliang.com A cookie is sent to the secondary nameservers for all requested static files.

If you want to support cookie-free image beds, you need to use a different domain name to achieve cookie-free.

  • Chen WeiliangBlog use www.chenweiliang.com 's subdomain is fine.

For details, please visit this article ▼

If you need to exclude 301 redirects to bypass pseudo-static exception folder directories, please view the tutorial below▼

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "Automatically jump to the second-level domain name without www top-level domain name: root domain name 301 redirects www", which is helpful to you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-27630.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top