{"id":3673,"date":"2016-05-11T18:52:55","date_gmt":"2016-05-11T22:52:55","guid":{"rendered":"https:\/\/underhost.com\/blog\/?p=3673"},"modified":"2026-10-23T08:55:42","modified_gmt":"2026-10-23T12:55:42","slug":"redirect-main-site-subfolder","status":"publish","type":"post","link":"https:\/\/underhost.com\/blog\/redirect-main-site-subfolder\/","title":{"rendered":"How to Point Your Main Domain to a Subfolder Without a Redirect Loop (.htaccess)"},"content":{"rendered":"<div class=\"uh-blog-hero\" style=\"margin:0 0 40px;text-align:center;padding:48px 24px;border-radius:20px;background:linear-gradient(135deg,#0D1F3C 0%,#125A8A 58%,#176EA5 100%);color:#ffffff;box-shadow:0 20px 40px -15px rgba(13,31,60,0.28);position:relative;overflow:hidden;\">\n<div style=\"display:inline-flex;align-items:center;gap:8px;padding:7px 14px;margin-bottom:16px;border:1px solid rgba(0,212,255,0.32);border-radius:999px;color:#DFF8FF;font-size:12px;font-weight:800;letter-spacing:.06em;text-transform:uppercase;background:rgba(0,212,255,0.10);\"><i class=\"fas fa-server\" style=\"color:#00D4FF;\"><\/i> Hosting Guide<\/div>\n<h1 style=\"color:#ffffff;font-size:clamp(32px,5vw,46px);line-height:1.12;margin:0 0 14px;font-weight:800;\">How to Point Your Main Domain to a Subfolder Without a Redirect Loop (.htaccess)<\/h1>\n<p style=\"font-size:18px;color:#EAF6FF;max-width:800px;margin:0 auto;line-height:1.7;\">Redirecting a domain to a subfolder requires precise .htaccess rules to prevent infinite loops. Learn how to configure your server correctly and ensure smooth redirection without breaking your website.<\/p>\n<\/div>\n<div class=\"uh-blog-excerpt\" style=\"border-left:4px solid #00D4FF;padding:18px 20px;margin:0 0 34px;background:#F8FAFC;color:#1F2937;border-radius:0 14px 14px 0;box-shadow:0 8px 28px rgba(13,31,60,0.08);line-height:1.75;\"><strong style=\"color:#0D1F3C;\">Short answer:<\/strong> Decide first whether visitors should <strong>see<\/strong> the subfolder in the address bar. To keep the address as <code>example.com<\/code> while serving files from <code>\/newfolder\/<\/code>, use an internal rewrite in <code>.htaccess<\/code> with a <code>RewriteCond %{REQUEST_URI} !^\/newfolder\/<\/code> line, which stops the loop. To send visitors to <code>example.com\/newfolder\/<\/code>, use a 301 redirect that applies only to the home page. Both versions are below, ready to copy.<\/div>\n<nav aria-label=\"Table of contents\" class=\"uh-toc\" style=\"background:#ffffff;border:1px solid #E5E7EB;border-radius:16px;padding:20px 22px;margin:0 0 34px;box-shadow:0 4px 12px rgba(13,31,60,0.08);\">\n<div style=\"font-size:12px;font-weight:800;letter-spacing:.06em;text-transform:uppercase;color:#176EA5;margin-bottom:10px;\"><i class=\"fas fa-list\" style=\"color:#00D4FF;\"><\/i> In this guide<\/div>\n<ol style=\"margin:0;padding-left:20px;columns:2 260px;column-gap:28px;line-height:1.9;\">\n<li><a href=\"#rewrite-or-redirect-which-do-you-need\" style=\"color:#176EA5;text-decoration:none;font-weight:600;\">Rewrite or redirect: which do you need?<\/a><\/li>\n<li><a href=\"#why-redirect-loops-happen\" style=\"color:#176EA5;text-decoration:none;font-weight:600;\">Why redirect loops happen<\/a><\/li>\n<li><a href=\"#option-1-serve-the-site-from-a-subfolder-address\" style=\"color:#176EA5;text-decoration:none;font-weight:600;\">Option 1: serve the site from a subfolder (address stays the same)<\/a><\/li>\n<li><a href=\"#option-2-send-visitors-to-the-subfolder-with-a-3\" style=\"color:#176EA5;text-decoration:none;font-weight:600;\">Option 2: send visitors to the subfolder with a 301 redirect<\/a><\/li>\n<li><a href=\"#wordpress-in-a-subfolder\" style=\"color:#176EA5;text-decoration:none;font-weight:600;\">WordPress in a subfolder<\/a><\/li>\n<li><a href=\"#why-not-use-cpanel-s-redirects-page\" style=\"color:#176EA5;text-decoration:none;font-weight:600;\">Why not use cPanel&#8217;s Redirects page?<\/a><\/li>\n<li><a href=\"#test-the-result\" style=\"color:#176EA5;text-decoration:none;font-weight:600;\">Test the result<\/a><\/li>\n<li><a href=\"#troubleshooting\" style=\"color:#176EA5;text-decoration:none;font-weight:600;\">Troubleshooting<\/a><\/li>\n<\/ol>\n<\/nav>\n<div class=\"uh-post-content\" style=\"color:#1F2937;font-size:16px;line-height:1.75;\">\n<h2 id=\"rewrite-or-redirect-which-do-you-need\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-angle-double-right\" style=\"color:#00D4FF;\"><\/i> Rewrite or redirect: which do you need?<\/h2>\n<div style=\"overflow-x:auto;margin:26px 0;border:1px solid #E5E7EB;border-radius:14px;-webkit-overflow-scrolling:touch;\">\n<table style=\"width:100%;border-collapse:collapse;background:#ffffff;color:#1F2937;font-size:15px;line-height:1.55;margin:0;min-width:600px;\">\n<thead>\n<tr style=\"background:#0D1F3C;color:#fff;\">\n<th style=\"padding:14px;text-align:left;\"><\/th>\n<th style=\"padding:14px;text-align:left;\">Internal rewrite<\/th>\n<th style=\"padding:14px;text-align:left;\">301 redirect<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Address bar shows<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\"><code>example.com\/page<\/code><\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\"><code>example.com\/newfolder\/page<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Visitor sees a change<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">No<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Yes, the URL changes<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Good for<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Keeping a site in a subfolder for tidiness, with clean URLs<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Moving the site to a new path for good<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">SEO<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">No change to URLs<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Search engines move rankings to the new URLs over time<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"margin:0 0 18px;\">Most people who ask for a &#8220;redirect to a subfolder&#8221; actually want the internal rewrite: the site lives in a folder, but visitors should not notice.<\/p>\n<h2 id=\"why-redirect-loops-happen\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-info-circle\" style=\"color:#00D4FF;\"><\/i> Why redirect loops happen<\/h2>\n<p style=\"margin:0 0 18px;\">A rule such as &#8220;send everything to <code>\/newfolder\/<\/code>&#8221; also matches requests that already point to <code>\/newfolder\/<\/code>. Apache applies the rule again, adds the folder again, and so on, until the browser stops with <strong>ERR_TOO_MANY_REDIRECTS<\/strong> or the server returns a 500 error. The fix is a condition that skips requests already inside the folder.<\/p>\n<h2 id=\"option-1-serve-the-site-from-a-subfolder-address\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-angle-double-right\" style=\"color:#00D4FF;\"><\/i> Option 1: serve the site from a subfolder (address stays the same)<\/h2>\n<p style=\"margin:0 0 18px;\">Open <code>public_html\/.htaccess<\/code> in cPanel&#8217;s File Manager, or create it, and add these lines at the top. Replace <code>example\\.com<\/code> with your domain (keep the backslash before the dot) and <code>newfolder<\/code> with your folder name.<\/p>\n<pre style=\"background:#0D1F3C;color:#EAF6FF;padding:18px 20px;border-radius:14px;overflow-x:auto;line-height:1.7;font-size:15px;\"><code>RewriteEngine On\n\n# Serve every request from \/newfolder\/, unless it already points there\nRewriteCond %{HTTP_HOST} ^(www\\.)?example\\.com$ [NC]\nRewriteCond %{REQUEST_URI} !^\/newfolder\/\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^(.*)$ \/newfolder\/$1 [L]\n\n# Serve the home page from the folder too\nRewriteCond %{HTTP_HOST} ^(www\\.)?example\\.com$ [NC]\nRewriteRule ^(\/)?$ newfolder\/index.php [L]<\/code><\/pre>\n<div style=\"overflow-x:auto;margin:26px 0;border:1px solid #E5E7EB;border-radius:14px;-webkit-overflow-scrolling:touch;\">\n<table style=\"width:100%;border-collapse:collapse;background:#ffffff;color:#1F2937;font-size:15px;line-height:1.55;margin:0;\">\n<thead>\n<tr style=\"background:#0D1F3C;color:#fff;\">\n<th style=\"padding:14px;text-align:left;\">Line<\/th>\n<th style=\"padding:14px;text-align:left;\">What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\"><code>RewriteCond %{HTTP_HOST}<\/code><\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Applies the rule only to your domain, not to addon domains in other folders.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\"><code>RewriteCond %{REQUEST_URI} !^\/newfolder\/<\/code><\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Skips requests that are already in the folder. This is what prevents the loop.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\"><code>!-f<\/code> and <code>!-d<\/code><\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Leaves real files and folders in <code>public_html<\/code> alone, for example verification files.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\"><code>RewriteRule ^(.*)$ \/newfolder\/$1 [L]<\/code><\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Serves the request from the folder, without changing the address.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\"><code>RewriteRule ^(\/)?$ newfolder\/index.php<\/code><\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Serves the home page, which the !-d check would otherwise skip.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"margin:0 0 18px;\">If your site&#8217;s start file is <code>index.html<\/code>, change <code>index.php<\/code> in the last line.<\/p>\n<h2 id=\"option-2-send-visitors-to-the-subfolder-with-a-3\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-angle-double-right\" style=\"color:#00D4FF;\"><\/i> Option 2: send visitors to the subfolder with a 301 redirect<\/h2>\n<p style=\"margin:0 0 18px;\">This changes the address in the browser. Redirect only the home page, so deeper links keep working:<\/p>\n<pre style=\"background:#0D1F3C;color:#EAF6FF;padding:18px 20px;border-radius:14px;overflow-x:auto;line-height:1.7;font-size:15px;\"><code>RewriteEngine On\nRewriteCond %{HTTP_HOST} ^(www\\.)?example\\.com$ [NC]\nRewriteRule ^$ \/newfolder\/ [R=301,L]<\/code><\/pre>\n<p style=\"margin:0 0 18px;\">Because the rule matches only the empty path (the home page), it cannot match <code>\/newfolder\/<\/code> again, so there is no loop. Test with a 302 (temporary) redirect first, then change it to 301, because browsers remember 301 redirects.<\/p>\n<h2 id=\"wordpress-in-a-subfolder\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-angle-double-right\" style=\"color:#00D4FF;\"><\/i> WordPress in a subfolder<\/h2>\n<p style=\"margin:0 0 18px;\">If the subfolder holds WordPress and you use Option 1, WordPress still builds links with the folder name unless you tell it otherwise:<\/p>\n<ol style=\"margin:0 0 24px;padding-left:22px;\">\n<li style=\"margin:0 0 8px;\">In <strong>Settings &gt; General<\/strong>, keep <strong>WordPress Address (URL)<\/strong> as <code>https:\/\/example.com\/newfolder<\/code>.<\/li>\n<li style=\"margin:0 0 8px;\">Set <strong>Site Address (URL)<\/strong> to <code>https:\/\/example.com<\/code>.<\/li>\n<li style=\"margin:0 0 8px;\">Save, then go to <strong>Settings &gt; Permalinks<\/strong> and click Save to refresh the rewrite rules.<\/li>\n<\/ol>\n<p style=\"margin:0 0 18px;\">WordPress&#8217;s own documentation calls this &#8220;giving WordPress its own directory&#8221;. Take a backup before you change these settings, because a wrong value can lock you out of the admin area.<\/p>\n<h2 id=\"why-not-use-cpanel-s-redirects-page\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-info-circle\" style=\"color:#00D4FF;\"><\/i> Why not use cPanel&#8217;s Redirects page?<\/h2>\n<p style=\"margin:0 0 18px;\">The Redirects page in cPanel is good for sending a whole domain or a page to another address. A wildcard redirect from a domain to a folder on the same domain, however, matches its own target and creates a loop. For a subfolder on the same domain, use the <code>.htaccess<\/code> rules above.<\/p>\n<h2 id=\"test-the-result\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-angle-double-right\" style=\"color:#00D4FF;\"><\/i> Test the result<\/h2>\n<pre style=\"background:#0D1F3C;color:#EAF6FF;padding:18px 20px;border-radius:14px;overflow-x:auto;line-height:1.7;font-size:15px;\"><code>curl -sI https:\/\/example.com\/ | head -n 5\ncurl -sI https:\/\/example.com\/about\/ | head -n 5<\/code><\/pre>\n<p style=\"margin:0 0 18px;\">With Option 1 you should get <code>200 OK<\/code> and no <code>Location<\/code> header. With Option 2, the home page should return <code>301<\/code> with <code>Location: \/newfolder\/<\/code>. Clear your browser cache, or use a private window, after each change.<\/p>\n<h2 id=\"troubleshooting\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-exclamation-triangle\" style=\"color:#00D4FF;\"><\/i> Troubleshooting<\/h2>\n<div style=\"overflow-x:auto;margin:26px 0;border:1px solid #E5E7EB;border-radius:14px;-webkit-overflow-scrolling:touch;\">\n<table style=\"width:100%;border-collapse:collapse;background:#ffffff;color:#1F2937;font-size:15px;line-height:1.55;margin:0;min-width:600px;\">\n<thead>\n<tr style=\"background:#0D1F3C;color:#fff;\">\n<th style=\"padding:14px;text-align:left;\">Problem<\/th>\n<th style=\"padding:14px;text-align:left;\">Likely cause<\/th>\n<th style=\"padding:14px;text-align:left;\">Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">ERR_TOO_MANY_REDIRECTS<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">The rule matches its own target, or another redirect (cPanel, plugin or HTTPS rule) conflicts<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Check the REQUEST_URI condition, and remove duplicate redirects in cPanel and plugins.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">500 Internal Server Error<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">A typing mistake in .htaccess<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Check the error log in cPanel and fix the line it names.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Images and CSS do not load<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">The site uses absolute paths with the folder name, or the folder is wrong<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Check the paths in the page source, and the folder name in the rules.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Addon domains break<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">The rule applies to every domain<\/td>\n<td style=\"padding:14px;border-top:1px solid #E5E7EB;vertical-align:top;\">Keep the HTTP_HOST condition so the rule only matches your main domain.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"margin:0 0 18px;\">For HTTPS and www redirects in the same file, see our <a href=\"https:\/\/underhost.com\/blog\/free-ssl-install-lets-encrypt-cpanel-centos-servers\/\">free SSL guide<\/a>. To edit .htaccess safely, see our <a href=\"https:\/\/underhost.com\/blog\/how-to-use-cpanels-file-manager-to-manage-your-website\/\">File Manager guide<\/a>.<\/p>\n<div aria-hidden=\"true\" class=\"uh-section-divider\" style=\"width:min(100% - 32px, 1080px);margin:44px auto;display:grid;grid-template-columns:1fr 32px 1fr;align-items:center;gap:18px;pointer-events:none;\"><span style=\"height:1px;background:linear-gradient(90deg,transparent,rgba(0,212,255,0.40),rgba(23,110,165,0.24),transparent);\"><\/span><img alt=\"\" decoding=\"async\" height=\"32\" loading=\"lazy\" src=\"https:\/\/cdn.underhost.com\/android-chrome-192x192.webp\" style=\"width:32px;height:32px;display:block;border-radius:8px;filter:drop-shadow(0 0 14px rgba(0,212,255,0.30));\" width=\"32\"\/><span style=\"height:1px;background:linear-gradient(90deg,transparent,rgba(23,110,165,0.24),rgba(0,212,255,0.40),transparent);\"><\/span><\/div>\n<\/div>\n<div class=\"uh-blog-cta\" style=\"background:linear-gradient(135deg,#0D1F3C 0%,#125A8A 58%,#176EA5 100%);color:#ffffff;padding:36px 24px;border-radius:20px;text-align:center;margin:44px 0;box-shadow:0 20px 40px -15px rgba(13,31,60,0.32);\">\n<h2 style=\"margin:0 0 12px;font-size:28px;line-height:1.25;color:#ffffff;\">Need help with this?<\/h2>\n<p style=\"font-size:17px;margin:0 auto 22px;color:#EAF6FF;max-width:720px;line-height:1.7;\">Need help with redirects or moving a site into a new folder? Our support team can check your rules.<\/p>\n<p><a href=\"https:\/\/underhost.com\/shared-hosting.php\" style=\"background:linear-gradient(90deg,#00D4FF,#0077FF);color:#ffffff;padding:13px 28px;border-radius:10px;text-decoration:none;font-weight:800;display:inline-block;margin:8px;\">See web hosting plans<\/a><a href=\"https:\/\/customerpanel.ca\/client\/\" style=\"background:transparent;color:#ffffff;padding:12px 28px;border-radius:10px;text-decoration:none;font-weight:800;display:inline-block;margin:8px;border:1px solid rgba(255,255,255,0.32);\">Contact @CustomerPanel<\/a><\/div>\n<div class=\"uh-faq-section\" id=\"faq\" style=\"margin:34px 0;scroll-margin-top:90px;\">\n<h2 style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:0 0 18px;border-bottom:2px solid rgba(0,212,255,0.22);padding-bottom:10px;\">Frequently asked questions<\/h2>\n<div style=\"margin-top:18px;background:#F8FAFC;padding:18px 20px;border-radius:14px;border:1px solid rgba(23,110,165,0.14);\">\n<h3 style=\"color:#0D1F3C;margin:0 0 8px;font-size:19px;\">How do I point my domain to a subfolder without changing the URL?<\/h3>\n<p style=\"margin:0;color:#1F2937;line-height:1.7;\">Use an internal rewrite in .htaccess with a condition that skips requests already in the folder, as shown in Option 1.<\/p>\n<\/div>\n<div style=\"margin-top:18px;background:#F8FAFC;padding:18px 20px;border-radius:14px;border:1px solid rgba(23,110,165,0.14);\">\n<h3 style=\"color:#0D1F3C;margin:0 0 8px;font-size:19px;\">Why does my redirect to a subfolder loop?<\/h3>\n<p style=\"margin:0;color:#1F2937;line-height:1.7;\">The rule also matches the folder itself. Add RewriteCond %{REQUEST_URI} !^\/newfolder\/ before the rule, or redirect only the home page.<\/p>\n<\/div>\n<div style=\"margin-top:18px;background:#F8FAFC;padding:18px 20px;border-radius:14px;border:1px solid rgba(23,110,165,0.14);\">\n<h3 style=\"color:#0D1F3C;margin:0 0 8px;font-size:19px;\">Should I use a 301 or a 302 redirect?<\/h3>\n<p style=\"margin:0;color:#1F2937;line-height:1.7;\">Test with a 302 first. Switch to a 301 once it works, because browsers and search engines remember 301 redirects.<\/p>\n<\/div>\n<div style=\"margin-top:18px;background:#F8FAFC;padding:18px 20px;border-radius:14px;border:1px solid rgba(23,110,165,0.14);\">\n<h3 style=\"color:#0D1F3C;margin:0 0 8px;font-size:19px;\">Can I change the document root of my main domain instead?<\/h3>\n<p style=\"margin:0;color:#1F2937;line-height:1.7;\">On shared hosting the main domain&#8217;s folder is fixed to public_html, so the .htaccess method is the usual way. On a VPS with WHM, the administrator can change it.<\/p>\n<\/div>\n<div style=\"margin-top:18px;background:#F8FAFC;padding:18px 20px;border-radius:14px;border:1px solid rgba(23,110,165,0.14);\">\n<h3 style=\"color:#0D1F3C;margin:0 0 8px;font-size:19px;\">Does this work with LiteSpeed?<\/h3>\n<p style=\"margin:0;color:#1F2937;line-height:1.7;\">Yes. LiteSpeed reads Apache .htaccess rewrite rules in the same way.<\/p>\n<\/div>\n<\/div>\n<p><!-- uh-related-start --><\/p>\n<div style=\"background:#F4F8FC;border:1px solid #DCE7F3;border-radius:14px;padding:18px 22px;margin:32px 0 8px;\">\n<h2 style=\"margin:0 0 12px;font-size:22px;\">Related guides<\/h2>\n<ul style=\"margin:0;padding-left:20px;\">\n<li style=\"margin:0 0 8px;\"><a href=\"https:\/\/underhost.com\/blog\/how-to-redirect-your-domain-to-a-subdirectory-without-creating-a-loop\/\">How to Redirect Your Domain to a Subdirectory Without Creating a Loop<\/a><\/li>\n<li style=\"margin:0 0 8px;\"><a href=\"https:\/\/underhost.com\/blog\/optimizing-database-performance-in-cpanel-for-faster-sites\/\">Optimizing Database Performance in cPanel for Faster Sites<\/a><\/li>\n<li style=\"margin:0 0 8px;\"><a href=\"https:\/\/underhost.com\/blog\/boosting-your-sites-load-speed-practical-tips-and-tools\/\">Boosting Your Site&#8217;s Load Speed: Practical Tips and Tools<\/a><\/li>\n<\/ul>\n<\/div>\n<p><!-- uh-related-end --><br \/>\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"How do I point my domain to a subfolder without changing the URL?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Use an internal rewrite in .htaccess with a condition that skips requests already in the folder, as shown in Option 1.\"}}, {\"@type\": \"Question\", \"name\": \"Why does my redirect to a subfolder loop?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"The rule also matches the folder itself. Add RewriteCond %{REQUEST_URI} !^\/newfolder\/ before the rule, or redirect only the home page.\"}}, {\"@type\": \"Question\", \"name\": \"Should I use a 301 or a 302 redirect?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Test with a 302 first. Switch to a 301 once it works, because browsers and search engines remember 301 redirects.\"}}, {\"@type\": \"Question\", \"name\": \"Can I change the document root of my main domain instead?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"On shared hosting the main domain's folder is fixed to public_html, so the .htaccess method is the usual way. On a VPS with WHM, the administrator can change it.\"}}, {\"@type\": \"Question\", \"name\": \"Does this work with LiteSpeed?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. LiteSpeed reads Apache .htaccess rewrite rules in the same way.\"}}]}<\/script><\/p>\n<h2 id=\"sources\" style=\"color:#0D1F3C;font-size:28px;line-height:1.25;margin:34px 0 14px;scroll-margin-top:90px;\"><i class=\"fas fa-book\" style=\"color:#00D4FF;\"><\/i> Sources<\/h2>\n<ul style=\"margin:0 0 24px;padding-left:22px;\">\n<li style=\"margin:0 0 8px;\"><a href=\"https:\/\/httpd.apache.org\/docs\/current\/mod\/mod_rewrite.html\">Apache documentation: mod_rewrite<\/a><\/li>\n<li style=\"margin:0 0 8px;\"><a href=\"https:\/\/developer.wordpress.org\/advanced-administration\/server\/wordpress-in-directory\/\">WordPress: giving WordPress its own directory<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Redirecting a domain to a subfolder requires precise .htaccess rules to prevent infinite loops. Learn how to configure your server correctly and ensure smooth redirection without breaking your website.<\/p>\n","protected":false},"author":1,"featured_media":5015,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[81],"tags":[108,123,185,129,116],"class_list":["post-3673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hosting-guides","tag-tag-cpanel","tag-tag-domains","tag-php","tag-tag-seo","tag-tag-wordpress"],"_links":{"self":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/comments?post=3673"}],"version-history":[{"count":8,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3673\/revisions"}],"predecessor-version":[{"id":6942,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3673\/revisions\/6942"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/media\/5015"}],"wp:attachment":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/media?parent=3673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/categories?post=3673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/tags?post=3673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}