When you need to permanently change the URL of a web page or your entire website, and you want your new and returning visitors and the search engines to find your new web page it’s recommended to use a search-engine friendly 301 redirect. A 301 redirect is the HTTP status code for “moved permanently”.
Major search engines are cracking down on websites that use sneaky redirects or point multiple domains to the same content without using a proper redirect. The 301 permanent redirect is known to be a search engine friendly redirect when needed.
Creating a 301 Permanent redirect with the .htaccess
file requires that your website is hosted on an Apache (Linux, Unix) based server. If you are unsure, a simple header check will indicate your server type.
If you are not certain you understand the server information provided from the header check, please contact your web host for assistance.
Have any of below questions? Want any of below redirection?
- WordPress 301 Redirect Via htaccess and FTP
- URL redirect rewrite using the htaccess file
- Simple Redirects with .htaccess
- Beginner’s Guide to Creating 301 Redirects in WordPress
- How to add URL Rewrite Rule To WordPress
- How to redirect wordpress page to another url htaccess
- WordPress 301 redirect htaccess rules
1. How to setup a simple 301 Redirect?
The basic code for redirecting is:
Redirect 301 old_location new_location
2. How to redirect a single page
Redirect 301 /oldpage.php http://www.yoursite.com/newpage.php Redirect 301 /oldpage2.php http://www.yoursite.com/folder/
3. Moved your domain to another site?
Option-1) You may want to redirect the whole site including complete URL
To do so, please open your .htaccess
file and add below to it. Just replace previousSite
and newSite
values.
RewriteEngine on RewriteCond %{HTTP_HOST} ^previousSite\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.previousSite\.com$ RewriteRule ^(.*)$ "http\:\/\/newSite\.com\/$1" [R=301,L]
Sample:
https://crunchify.com/Test1 will be redirected to https://xyz.crunchify.com/Test1
Long time back I moved my blog to new domain from Crunchify.co
to Crunchify.com
. I’ve explained the steps which I followed to move it in 30 mins. This was long time back. I don’t own Crunchify.co anymore.
Get more information here: https://crunchify.com/wordpress-tips-move-your-blog-from-one-domain-to-another/
Option-2) You may want to redirect site to only home page of the new domain
RewriteEngine on RewriteCond %{HTTP_HOST} ^test\.crunchify\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.test\.crunchify\.com$ RewriteRule ^(.*)$ "http\:\/\/crunchify\.com\/" [R=301,L]
Sample:
https://test.crunchify.com/Test1 will be redirected to https://crunchify.com/
4. Best way to redirect an entire site to a sub folder
Redirect 301 / https://crunchify.com/subfolder/
5. Best way to redirect a sub folder to different website?
Redirect 301 /subfolder https://crunchify.com/
6. Best way to redirect only a file extension but retain the page name?
RedirectMatch 301 (.*)\.php$ https://crunchify.com$1.html
7. Best way to redirect from a non-www to www subdomain?
RewriteEngine on RewriteBase / rewritecond %{http_host} ^crunchify.com [nc] rewriterule ^(.*)$ http://www.crunchify.com/$1 [r=301,nc]
8. Best way to redirect from an old domain to new domain that includes the full path and query string
Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*) https://www.domain.com%{REQUEST_URI} [R=302,NC]
9. How to Redirect Site from HTTP to HTTPS and from HTTPS to HTTP?
Checkout this detailed tutorial.
How to redirect any incoming request from non-secure (HTTP) to secure (HTTPS) call?
10. How to redirect from a blog sub domain to to a blog folder?
Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_URI}/ blog RewriteRule ^(.*) https://crunchify.com/%{REQUEST_URI} [R=302,NC] RewriteRule ^(.*) https://crunchify.com/blog/%{REQUEST_URI} [R=302,NC]
Let me know if you have any question on above rules. If you want to contribute to this rules then feel free to update us via comment section below.