{"id":2676,"date":"2019-07-02T16:19:42","date_gmt":"2019-07-02T10:49:42","guid":{"rendered":"https:\/\/www.24x7serversupport.com\/blog\/?p=2676"},"modified":"2019-07-02T17:02:48","modified_gmt":"2019-07-02T11:32:48","slug":"htaccess-tips-and-tricks","status":"publish","type":"post","link":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/","title":{"rendered":"Htaccess tips and tricks"},"content":{"rendered":"\n<p>Block IP:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;RequireAll&gt;\n    Require all granted\n    Require not ip 1.2.3.4\n&lt;\/RequireAll&gt;\n<\/pre>\n\n\n\n<p>Force www, or non www, redirect.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#Force www:\nRewriteEngine on\nRewriteCond&nbsp;%{HTTP_HOST} ^example.com [NC]\nRewriteRule ^(.*)$ http:\/\/www.example.com\/$1 [L,R=301,NC]#Force www:\n\n#Force non-www:\nRewriteEngine on\nRewriteCond&nbsp;%{HTTP_HOST} ^www\\.example\\.com [NC]\nRewriteRule ^(.*)$ http:\/\/example.com\/$1 [L,R=301]\n<\/pre>\n\n\n\n<p>Redirect all traffic to SSL site.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">RewriteEngine on\nRewriteCond&nbsp;%{SERVER_PORT}&nbsp;!443 [NC]\nRewriteRule (.*) <a href=\"https:\/\/%25%7Bserver_name%7D\/$1\">https:\/\/%{SERVER_NAME}\/$1<\/a> [R,L,QSA]<\/pre>\n\n\n\n<p>Redirect iPhones:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">RewriteEngine on\nRewriteCond&nbsp;%{HTTP_USER_AGENT} iPhone\nRewriteCond&nbsp;%{REQUEST_URI}&nbsp;!^\/my-iPhone-site\/ \nRewriteRule .* \/my-iPhone-site\/ [R]\n<\/pre>\n\n\n\n<p>Block access by file extension:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;Files ~ \"\\.inc$\"&gt;\nOrder allow,deny\nDeny from all\n&lt;\/Files&gt;\n\nOr:\n&lt;FilesMatch \"\\.(htaccess|htpasswd|ini|log|sh|inc|bak)$\"&gt;\nOrder Allow,Deny\nDeny from all\n&lt;\/FilesMatch&gt;\n<\/pre>\n\n\n\n<p>Redirect based on query string:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">RewriteCond&nbsp;%{QUERY_STRING} option=com_xius&amp;view=list&amp;listid=19&amp;task=showList&amp;Itemid=3163 [NC]\nRewriteRule ^index.php <a href=\"http:\/\/www.example.com\/page-name\">http:\/\/www.example.com\/page-name<\/a> [QSD,L,R=301]\n<\/pre>\n\n\n\n<p>Password protect directory using 2.4 directives:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;RequireAny&gt;\n  &lt;RequireAll&gt;\n    AuthType Basic\n    AuthName \"Password Protected\"\n    AuthUserFile \/home\/perfumes\/.htpasswds\/public_html\/devspace\/passwd\n    Require valid-user\n  &lt;\/RequireAll&gt;\n&lt;\/RequireAny&gt;\n<\/pre>\n\n\n\n<p>For Apache 2.2 Just remove the &#8220;Require&#8221; lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">AuthType Basic\nAuthName \"Password Protected\"\nAuthUserFile \/home\/perfumes\/.htpasswds\/public_html\/devspace\/passwd\nRequire valid-user\n<\/pre>\n\n\n\n<p>Redirect old domain to a new domain.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">RewriteEngine on\nRewriteCond&nbsp;%{HTTP_HOST} ^example.com [NC,OR]\nRewriteCond&nbsp;%{HTTP_HOST} ^www.example.com [NC]\nRewriteRule ^(.*)$ http:\/\/example2.com\/$1 [L,R=301,NC]\n<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">RewriteEngine On\nRewriteRule ^ftp\/pub\/(.*)$ \/repos\/$1 [NC,L]\nRewriteRule ^pub\/(.*)$ \/repos\/$1 [NC,L]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Block IP: &lt;RequireAll&gt; Require all granted Require not ip 1.2.3.4 &lt;\/RequireAll&gt; Force www, or non www, redirect. #Force www: RewriteEngine on RewriteCond&nbsp;%{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ http:\/\/www.example.com\/$1 [L,R=301,NC]#Force www: #Force non-www: RewriteEngine on RewriteCond&nbsp;%{HTTP_HOST} ^www\\.example\\.com [NC] RewriteRule ^(.*)$ http:\/\/example.com\/$1 [L,R=301] Redirect all traffic to SSL site. RewriteEngine on RewriteCond&nbsp;%{SERVER_PORT}&nbsp;!443 [NC] RewriteRule (.*) https:\/\/%{SERVER_NAME}\/$1 [R,L,QSA] Redirect [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2679,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[139,30],"tags":[119,31,192],"class_list":["post-2676","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache","category-centos","tag-apache","tag-centos","tag-htaccess"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Htaccess tips and tricks | 24x7serversupport Blog<\/title>\n<meta name=\"description\" content=\"Htaccess tips and tricks, How to block IP using .htaccess, htaccess redirection code, HTTP to HTTPs redirection using .htaccess\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Htaccess tips and tricks | 24x7serversupport Blog\" \/>\n<meta property=\"og:description\" content=\"Htaccess tips and tricks, How to block IP using .htaccess, htaccess redirection code, HTTP to HTTPs redirection using .htaccess\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/\" \/>\n<meta property=\"og:site_name\" content=\"24x7serversupport Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-02T10:49:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-02T11:32:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"904\" \/>\n\t<meta property=\"og:image:height\" content=\"199\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"24x7support\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@24x7serversuppo\" \/>\n<meta name=\"twitter:site\" content=\"@24x7serversuppo\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"24x7support\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/\",\"name\":\"Htaccess tips and tricks | 24x7serversupport Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1\",\"datePublished\":\"2019-07-02T10:49:42+00:00\",\"dateModified\":\"2019-07-02T11:32:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401\"},\"description\":\"Htaccess tips and tricks, How to block IP using .htaccess, htaccess redirection code, HTTP to HTTPs redirection using .htaccess\",\"breadcrumb\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1\",\"width\":904,\"height\":199},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.24x7serversupport.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Htaccess tips and tricks\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#website\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/\",\"name\":\"24x7serversupport Blog\",\"description\":\"Linux | CPanel | WHM | webhosting| Plesk | DirectAdmin | CentOs | Debian | Ubuntu Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.24x7serversupport.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401\",\"name\":\"24x7support\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/author\/24x7support\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Htaccess tips and tricks | 24x7serversupport Blog","description":"Htaccess tips and tricks, How to block IP using .htaccess, htaccess redirection code, HTTP to HTTPs redirection using .htaccess","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/","og_locale":"en_US","og_type":"article","og_title":"Htaccess tips and tricks | 24x7serversupport Blog","og_description":"Htaccess tips and tricks, How to block IP using .htaccess, htaccess redirection code, HTTP to HTTPs redirection using .htaccess","og_url":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/","og_site_name":"24x7serversupport Blog","article_published_time":"2019-07-02T10:49:42+00:00","article_modified_time":"2019-07-02T11:32:48+00:00","og_image":[{"width":904,"height":199,"url":"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1","type":"image\/jpeg"}],"author":"24x7support","twitter_card":"summary_large_image","twitter_creator":"@24x7serversuppo","twitter_site":"@24x7serversuppo","twitter_misc":{"Written by":"24x7support","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/","url":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/","name":"Htaccess tips and tricks | 24x7serversupport Blog","isPartOf":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#primaryimage"},"image":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1","datePublished":"2019-07-02T10:49:42+00:00","dateModified":"2019-07-02T11:32:48+00:00","author":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401"},"description":"Htaccess tips and tricks, How to block IP using .htaccess, htaccess redirection code, HTTP to HTTPs redirection using .htaccess","breadcrumb":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#primaryimage","url":"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1","width":904,"height":199},{"@type":"BreadcrumbList","@id":"https:\/\/www.24x7serversupport.com\/blog\/htaccess-tips-and-tricks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.24x7serversupport.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Htaccess tips and tricks"}]},{"@type":"WebSite","@id":"https:\/\/www.24x7serversupport.com\/blog\/#website","url":"https:\/\/www.24x7serversupport.com\/blog\/","name":"24x7serversupport Blog","description":"Linux | CPanel | WHM | webhosting| Plesk | DirectAdmin | CentOs | Debian | Ubuntu Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.24x7serversupport.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401","name":"24x7support","url":"https:\/\/www.24x7serversupport.com\/blog\/author\/24x7support\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.24x7serversupport.com\/blog\/wp-content\/uploads\/2019\/07\/24x7serversupport_htaccess_tips_tricks.jpg?fit=904%2C199&ssl=1","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/2676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/comments?post=2676"}],"version-history":[{"count":3,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/2676\/revisions"}],"predecessor-version":[{"id":2680,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/2676\/revisions\/2680"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/media\/2679"}],"wp:attachment":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/media?parent=2676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/categories?post=2676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/tags?post=2676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}