{"id":215,"date":"0206-12-11T18:23:28","date_gmt":"0206-12-11T18:23:28","guid":{"rendered":"https:\/\/www.xsofthost.com\/Blogs\/?p=215"},"modified":"2017-09-01T12:18:31","modified_gmt":"2017-09-01T12:18:31","slug":"how-to-use-rewritecond-and-rewriterule-in-htaccess","status":"publish","type":"post","link":"https:\/\/www.xsofthost.com\/help\/how-to-use-rewritecond-and-rewriterule-in-htaccess\/","title":{"rendered":"How to use RewriteCond and RewriteRule in .htaccess"},"content":{"rendered":"<p>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 , &#8220;which is very important for google ranking and SEO&#8221;.<\/p>\n<p>by editing the file using notepad or any plain editor :<\/p>\n<p>First you have to enable the Rewrite Engine\u00a0 on the .htaccess file as bellow:<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">RewriteEngine on <\/pre>\n<p>To redirect from yourdomain.com to www.yourdomain.com<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nRewriteCond %{HTTP_HOST} !^www\\.(.*)$ [NC]\r\nRewriteRule ^(.*)$ https:\/\/www.%{HTTP_HOST}\/$1 [R=301,L]<\/pre>\n<p>To force your website for using <strong>HTTPS <\/strong>using <strong>WWW <\/strong>incase you have install SSL<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nRewriteCond %{HTTPS} !=on\r\nRewriteRule ^(.*)$ https:\/\/www.yourdomainname.com\/$1 [L,R=301]  <\/pre>\n<p>Redirecting www to non-www<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nRewriteCond %{HTTP_HOST} !^yourdomain\\.com$ [NC]\r\nRewriteRule ^(.*)$ http:\/\/yourdomain.com\/$1 [R=301,L]<\/pre>\n<p>Redirect <strong>www<\/strong> urls to<strong> non-www<\/strong> with <strong>https<\/strong><\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nRewriteCond %{HTTP_HOST} ^www\\.(.*)$ [NC]\r\nRewriteRule ^(.*)$ https:\/\/%1\/$1 [R=301,L]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 , &#8220;which is very important for google ranking and SEO&#8221;. by editing the file using notepad or any plain editor : First you have to enable the Rewrite Engine\u00a0 on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":274,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[32,178,33,74],"_links":{"self":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/215"}],"collection":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":13,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":275,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/215\/revisions\/275"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/media\/274"}],"wp:attachment":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}