{"id":16304,"date":"2024-10-31T10:17:43","date_gmt":"2024-10-31T10:17:43","guid":{"rendered":"https:\/\/truehost.com\/support\/?post_type=docs&#038;p=16304"},"modified":"2024-10-31T11:36:43","modified_gmt":"2024-10-31T11:36:43","password":"","slug":"how-to-configure-apache-redirects-with-htaccess-files","status":"publish","type":"docs","link":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/","title":{"rendered":"How to Configure Apache Redirects with .htaccess Files"},"content":{"rendered":"\n<h6 class=\"wp-block-heading\">Configuring redirects in Apache using <code>.htaccess<\/code> files is a common way to manage URL changes, handle SEO needs, and improve user experience. The <code>.htaccess<\/code> file allows you to configure web server settings on a per-directory basis, making it easy to create redirects without altering the main server configuration.<\/h6>\n\n\n\n<p>Here&#8217;s a guide on how to set up various types of redirects using <code>.htaccess<\/code> files.<\/p>\n\n\n\n<p><strong>Step 1: Locate or Create the <code>.htaccess<\/code> File<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Navigate to the root directory of your website, typically <code>\/var\/www\/html<\/code> or similar.<\/li>\n\n\n\n<li>If a <code>.htaccess<\/code> file doesn&#8217;t exist, create one:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>touch .htaccess<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure the file has the correct permissions, so it\u2019s readable by the web server:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 644 .htaccess<\/code><\/pre>\n\n\n\n<p><strong>Step 2: Enable <code>.htaccess<\/code> Usage in Apache<\/strong><\/p>\n\n\n\n<p>Before <code>.htaccess<\/code> files can be used, ensure that your Apache configuration allows it. Open the Apache configuration file (usually in <code>\/etc\/apache2\/apache2.conf<\/code> or <code>\/etc\/httpd\/conf\/httpd.conf<\/code>), and make sure the <code>AllowOverride<\/code> directive is set to <code>All<\/code> for the directory where you want <code>.htaccess<\/code> to work.<\/p>\n\n\n\n<p>Example configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \/var\/www\/html>\n    AllowOverride All\n&lt;\/Directory><\/code><\/pre>\n\n\n\n<p>After editing, restart Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2   # Ubuntu\/Debian\nsudo systemctl restart httpd     # CentOS\/RHEL<\/code><\/pre>\n\n\n\n<p><strong>Step 3: Configure Redirects in <code>.htaccess<\/code><\/strong><\/p>\n\n\n\n<p>There are various types of redirects you can set up with <code>.htaccess<\/code>. Here are the most commonly used ones:<\/p>\n\n\n\n<p>1. <strong>Simple Redirects<\/strong> (301 Permanent and 302 Temporary Redirects)<\/p>\n\n\n\n<p><strong>301 Redirect (Permanent):<\/strong> A 301 redirect tells search engines that the URL has permanently moved.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Redirect 301 \/old-page https:\/\/example.com\/new-page<\/code><\/pre>\n\n\n\n<p><strong>302 Redirect (Temporary):<\/strong> A 302 redirect indicates the change is temporary.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Redirect 302 \/old-page https:\/\/example.com\/new-page<\/code><\/pre>\n\n\n\n<p>2. <strong>Redirect All Traffic to HTTPS<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to redirect all traffic from HTTP to HTTPS:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;L,R=301]<\/code><\/pre>\n\n\n\n<p>3. <strong>Redirect a Domain to Another Domain<\/strong><\/p>\n\n\n\n<p>To redirect an entire domain to another domain:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\nRewriteCond %{HTTP_HOST} ^oldexample\\.com$ &#91;NC]\nRewriteRule ^(.*)$ https:\/\/newexample.com\/$1 &#91;L,R=301]<\/code><\/pre>\n\n\n\n<p>4. <strong>Redirect a Specific Page<\/strong><\/p>\n\n\n\n<p>To redirect only a specific page, use the following syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Redirect 301 \/old-page.html \/new-page.html<\/code><\/pre>\n\n\n\n<p>This assumes that both pages are on the same domain. For different domains, specify the full URL of the new page.<\/p>\n\n\n\n<p>5. <strong>Redirect a Directory to Another Directory<\/strong><\/p>\n\n\n\n<p>If you want to redirect an entire directory, such as <code>\/old-directory<\/code>, to a new location, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Redirect 301 \/old-directory \/new-directory<\/code><\/pre>\n\n\n\n<p>Or, if the directory is on another domain:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Redirect 301 \/old-directory https:\/\/example.com\/new-directory<\/code><\/pre>\n\n\n\n<p><strong>Step 4: Test the Redirects<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Clear your browser cache to ensure the changes are loaded.<\/li>\n\n\n\n<li>Navigate to the old URLs to confirm that they redirect as expected.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Example <code>.htaccess<\/code> File<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Enable Rewrite Engine\nRewriteEngine On\n\n# Redirect HTTP to HTTPS\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;L,R=301]\n\n# Redirect old page to new page\nRedirect 301 \/old-page https:\/\/example.com\/new-page\n\n# Redirect entire domain\nRewriteCond %{HTTP_HOST} ^oldexample\\.com$ &#91;NC]\nRewriteRule ^(.*)$ https:\/\/newexample.com\/$1 &#91;L,R=301]\n\n# Redirect directory\nRedirect 301 \/old-directory https:\/\/example.com\/new-directory<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Configuring redirects in Apache using .htaccess files is a common way to manage URL changes, handle SEO needs, and improve user experience. The .htaccess file allows you to configure web server settings on a per-directory basis, making it easy to create redirects without altering the main server configuration. Here&#8217;s a guide on how to set [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_eb_attr":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_category":[1820,1824,1879,2128],"doc_tag":[],"class_list":["post-16304","docs","type-docs","status-publish","hentry","doc_category-cloud-servers-in-kenya","doc_category-dedicated-servers","doc_category-servers","doc_category-vps-servers"],"year_month":"2026-06","word_count":477,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"Eugene","author_nicename":"eugene","author_url":"https:\/\/truehost.com\/support\/author\/eugene\/"},"doc_category_info":[{"term_name":"Cloud servers in Kenya","term_url":"https:\/\/truehost.com\/support\/docs-category\/cloud-servers-in-kenya\/"},{"term_name":"dedicated servers","term_url":"https:\/\/truehost.com\/support\/docs-category\/dedicated-servers\/"},{"term_name":"Servers","term_url":"https:\/\/truehost.com\/support\/docs-category\/servers\/"},{"term_name":"VPS-Servers","term_url":"https:\/\/truehost.com\/support\/docs-category\/vps-servers\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Configure Apache Redirects with .htaccess Files -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Configure Apache Redirects with .htaccess Files -\" \/>\n<meta property=\"og:description\" content=\"Configuring redirects in Apache using .htaccess files is a common way to manage URL changes, handle SEO needs, and improve user experience. The .htaccess file allows you to configure web server settings on a per-directory basis, making it easy to create redirects without altering the main server configuration. Here&#8217;s a guide on how to set [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-31T11:36:43+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-apache-redirects-with-htaccess-files\\\/\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-apache-redirects-with-htaccess-files\\\/\",\"name\":\"How to Configure Apache Redirects with .htaccess Files -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#website\"},\"datePublished\":\"2024-10-31T10:17:43+00:00\",\"dateModified\":\"2024-10-31T11:36:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-apache-redirects-with-htaccess-files\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-apache-redirects-with-htaccess-files\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-apache-redirects-with-htaccess-files\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Configure Apache Redirects with .htaccess Files\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#website\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\",\"name\":\"\",\"description\":\"Help In a Click\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#organization\",\"name\":\"Truehost Kenya\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"contentUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"width\":240,\"height\":48,\"caption\":\"Truehost Kenya\"},\"image\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Configure Apache Redirects with .htaccess Files -","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:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure Apache Redirects with .htaccess Files -","og_description":"Configuring redirects in Apache using .htaccess files is a common way to manage URL changes, handle SEO needs, and improve user experience. The .htaccess file allows you to configure web server settings on a per-directory basis, making it easy to create redirects without altering the main server configuration. Here&#8217;s a guide on how to set [&hellip;]","og_url":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/","article_modified_time":"2024-10-31T11:36:43+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/","url":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/","name":"How to Configure Apache Redirects with .htaccess Files -","isPartOf":{"@id":"https:\/\/www.truehost.com\/support\/#website"},"datePublished":"2024-10-31T10:17:43+00:00","dateModified":"2024-10-31T11:36:43+00:00","breadcrumb":{"@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-configure-apache-redirects-with-htaccess-files\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.truehost.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to Configure Apache Redirects with .htaccess Files"}]},{"@type":"WebSite","@id":"https:\/\/www.truehost.com\/support\/#website","url":"https:\/\/www.truehost.com\/support\/","name":"","description":"Help In a Click","publisher":{"@id":"https:\/\/www.truehost.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.truehost.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.truehost.com\/support\/#organization","name":"Truehost Kenya","url":"https:\/\/www.truehost.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.truehost.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","contentUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","width":240,"height":48,"caption":"Truehost Kenya"},"image":{"@id":"https:\/\/www.truehost.com\/support\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/16304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/comments?post=16304"}],"version-history":[{"count":3,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/16304\/revisions"}],"predecessor-version":[{"id":16308,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/16304\/revisions\/16308"}],"wp:attachment":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/media?parent=16304"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_category?post=16304"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_tag?post=16304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}