Apache

How to use RewriteCond and RewriteRule in .htaccess

You can use .htaccess file that located on the root of your web site to make versions or make one version of your web pages , “which is very important for google ranking and SEO”.

by editing the file using notepad or any plain editor :

First you have to enable the Rewrite Engine  on the .htaccess file as bellow:

RewriteEngine on 

To redirect from yourdomain.com to www.yourdomain.com

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

To force your website for using HTTPS using WWW incase you have install SSL

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.yourdomainname.com/$1 [L,R=301]  

Redirecting www to non-www

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

Redirect www urls to non-www with https

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
XsoftHost Support

Share

Recent Posts

Add Extra IP addresses to server configuration On Ubuntu 17.10 and later

Each failover IP address will need its own line in the configuration file. The configuration…

4 years ago

Create RAID Arrays with mdadm on Ubuntu

What is mdadm? The mdadm utility can be used to create and manage storage arrays…

4 years ago

How to change the maximum upload file size for PHP

There are several scenarios that you might need to increase or decrease your php maximum…

6 years ago

How to install Let’s Encrypt Plugin in WHM/cPanel

What is Let’s Encrypt? Let’s Encrypt is a free certificate authority provided by the Internet…

6 years ago

How to install python in my cPanel and add py extension

Python normally installed on all cPanel hosting server because most of Centos/red hat update system…

6 years ago

How to install and enable GUI GNOME Desktop on centos 7

Usually CentOS 7 comes in a numbers of variants, For most users, there are two…

6 years ago