What is a 301 redirect?
When you view a website page, you may see a message telling you that the page has moved elsewhere. This is what a 301 redirect does. It’s like a “we’ve moved over there” indication to browsers and search engines.
Let’s take a simple example to explain. Suppose you have an old website with a popular article at techchris.net/old-article, but you decide to migrate the article to a new website structure and change the URL to techchris.net/new-article.
If someone enters the old URL techchris.net/old-article into their browser, they may get an error page because that page no longer exists on the old site. However, by using a 301 redirect, you can tell browsers and search engines, “This article has been moved to the new URL techchris.net/new-article, please send your request here”.
When browsers or search engines receive the response to this 301 redirect, they will automatically send the request to the new URL instead of continuing to request the old one. this way, users can access your new article without any problem and search engines can index it correctly.
To summarize, a 301 redirect is like a “URL move address notification” that tells browsers and search engines that the page has been permanently moved to another address. It ensures that users don’t see the wrong page and helps search engines index the site’s pages correctly.
301 redirect operation method
- Check that the new website is configured and accessible properly.
- Log in to the backend of your old website, find the .htaccess file (usually in the root directory) and add the following rules to the .htaccess file:
RewriteEngine On RewriteRule ^(.*)$ https://techchris.net/$1 [R=301,L]
Replace techchris.net in the above code with the domain name of your new website.
! If the .htaccess file does not exist
Then you can go to the dashboard of WordPress, go to >> “Settings” >> “Permilinks” page, and click “Save Changes” button directly.
This code is a basic redirect rule on an Apache server that uses the mod_rewrite module for URL rewriting and redirection. Let me explain the code in detail:
RewriteEngine On
: This is a directive that enables Apache’s mod_rewrite module. It tells the server to enable URL rewriting.RewriteRule ^(. *)$ https://techchris.net/$1 [R=301,L]
: This is a redirect rule that defines the URL pattern to be redirected and the target URL.RewriteRule
: This is the start tag for a rewrite rule.^(. *)$
: This is a regular expression pattern that matches the path of the requested URL.^
indicates the beginning of the string,. *
means match any character zero or more times, and$
means the end of the string. Thus,^(. *)$
matches any URL path.http://example.com/$1
: This is the target URL to redirect to.$1
represents the capture group in the regular expression (i.e., the contents of the parentheses). In this case, the capture group is(. *)
, which matches the part of the requested URL path. So,$1
will be replaced with the requested URL path.[R=301,L]
: This is the option for the redirect rule.R=301
means that a 301 permanent redirect status code is used, telling browsers and search engines that the redirect is permanent.L
means that this is the last rule, and if the match is successful, the execution of the other rules will be stopped.
Views: 94