We can redirect any webpage to any other or redirect the whole domain or website to another using HTACCESS.
Index
.HTACCESS file manages settings for the PHP server. Also, it can manage PHP file routes. There are various types of HTACCESS redirects, as mentioned below.
This method is a permanent redirect method used to indicate a search engine to move from the originating URL to a new URL permanently. This method is the best for implementing URL redirect for the website. Here, code 301 represents the HTTP status code for the web.
Note: This method is the most friendly website redirection method for search engines.
Syntax
RewriteEngine on
RewriteCond %{http_host}^yourdomain.com[nc]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]
Note: Replace yourdomain.com with your domain name.
This method is used for the following purpose:
This method is a temporary redirect method. It is mainly useful for SEO purposes. When the user has a temporary landing page, and the user plans to switch back to the main landing page after time.
Example
Redirect www.errorsea.com to http://demo.errorsea.com using this method.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.errorsea\.com$ [NC]
RewriteRule ^(.*)$ http://demo.errorsea.com/ [L,R=302]
This method is used for the following purpose:
This method uses the GET method. It informs the server to fetch the information on the server.
Note: This method was used for preventing a form resubmission after the HTTP POST request.
Suppose the user bookmarks the page, then it doesn’t show the user data submitted. Instead, this method shows him/her a page saying, “your data submitted successfully.”
This method is used for the following purpose:
This method is also a temporary redirect method like 303 redirects, but it is a non-cacheable method as default.
We can use this method to temporarily redirect a new URL to preserve the original URL request’s request methods.
Note: If the redirect is permanent, then this method should be avoided.
It shouldn’t use with a PRG pattern.
This method is cacheable by default if the user doesn’t indicate it. This method can be used to handle the request method from the original request for the subsequent request.
For example, redirect of form action URLs using the POST method.
Note: This method is the wrong choice for all occasions in which catchability can leads the user to unexpected negative behavior.
This method is used for the following purpose:
Read More: How to Redirect Page in PHP [All Methods]
In this article, we learned all types of HTACCESS redirect methods in great detail.
Enjoy Programming 🙂
There is a reason big-name companies like CNN use WordPress. WordPress is a popular content…
In this tutorial, I'm going to show you how to install MySQL on your computer.…
Download Turbo C++ for windows 10 in just 7 Mb and run your first C++…
There are lots of methods to redirect pages, like refresh-redirect from META tag, redirect from…
Include files in PHP are used in appending various global or config files. We can…
Hey Angular geek, if you are also having Error TS2305: Module ‘”{FilePath}/app.component”’ Has No Exported…