Header Ads Widget

Ticker

6/recent/ticker-posts

Top 5 HTACCESS Redirect Url Techniques

 

Top 5 HTACCESS Redirect URL Techniques



HTACCESS is used to restrict access to Files, URLs, Rewrite URLs, configure Error pages, enabling GZIP or compression, and more. You can redirect all of the requests for the domain (domain.com) to (www.domain.com) by editing your website's .htaccess file in cPanel. You need to add the following code at the beginning of the file in order to set up that redirection in the .htaccess file.

                                                  Open Cpanel
c-panel1


Make sure that the Show Hidden Files (dotfiles) option is enabled in the Settings menu

c-panel2

Locate .htaccess file, right-click > Edit


c-panel3


If there is no .htaccess file located in your File manager, feel free to create a new one using the File option

C-Panel4



Below are the 6 different types of redirect.


1. Redirect HTTP to HTTPS Type

HTTPS offers end to end encryption between the server and the browser. You should set up a Redirect from HTTP to HTTPS after installing the SSL certificate. You can either check for HTTPS ON/OFF condition or HTTPS 443 Port status. You can directly Copy-Paste the below template.

<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
 

2. Redirect Non-WWW to WWW URL Type


CMS (Content Management Systems) software prompts developers for the first time to choose from Prefixed WWW and Non-WWW versions. Famous CRMs are WordPress, Joomla, and Drupal. Maintaining a single version of the URL is a good SEO point of view.

Replace the SITE URLs "abc.com" and "http://www.abc.com" with your working site URLs.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
</IfModule>


3. Redirect Page A to Page B Vice Versa


If you want to put a Forward Rule from one page to another, you should include the relative path in the .htaccess file. It means, both the URLs are on the same working domain. A leading Forward-Slash is mandatory.

Replace "page-a" and "page-b" with your site pages.

<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /page-a /Page-b
</IfModule>
 

4. 404 (Page Not Found) to Custom Error Page

 A custom error page for 404 Page Found Errors looks good for visitors. It easily informs users that something is wrong with the URL or the address.

Replace the Page URL "www.abc.com/errpage" with your Error Page URL.

<IfModule mod_rewrite.c>
RewriteEngine On
ErrorDocument 404 www.yourdomain.com/errpage
</IfModule>



5. Method for 301 redirects for page redirect.

Create New Page with Old page name and paste the below code on the page.

 

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=https://yourdomain.com/new-page">
</head>
<body>
</body>
</html>

Post a Comment

0 Comments