Warning: session_start(): open(/var/cpanel/php/sessions/alt-php74/sess_1a8d5453b8be5daa366261776c7e8b4f, O_RDWR) failed: No such file or directory (2) in /home/xsofthost/public_html/help/wp-content/plugins/accelerated-mobile-pages/includes/redirect.php on line 358

Warning: session_start(): Failed to read session data: files (path: /var/cpanel/php/sessions/alt-php74) in /home/xsofthost/public_html/help/wp-content/plugins/accelerated-mobile-pages/includes/redirect.php on line 358
How to use RewriteCond and RewriteRule in .htaccess - XsoftHost

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]
Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp

Related Posts