{"id":3673,"date":"2016-05-11T18:52:55","date_gmt":"2016-05-11T22:52:55","guid":{"rendered":"https:\/\/underhost.com\/blog\/?p=3673"},"modified":"2025-03-12T05:16:55","modified_gmt":"2025-03-12T09:16:55","slug":"redirect-main-site-subfolder","status":"publish","type":"post","link":"https:\/\/underhost.com\/blog\/redirect-main-site-subfolder\/","title":{"rendered":"How to Redirect Your Main Site to a Subfolder Without Causing a Loop"},"content":{"rendered":"<h2>Redirecting Your Main Site to a Subfolder the Right Way<\/h2>\n<p>If you need to redirect <strong>http:\/\/www.yourdomain.com<\/strong> to <strong>http:\/\/www.yourdomain.com\/subdirectory\/<\/strong> without causing a redirect loop, you must configure your <code>.htaccess<\/code> file properly. Below is the correct method to achieve this.<\/p>\n<h3>1. Add This Code to Your .htaccess File<\/h3>\n<p>Place the following rules in the <code>.htaccess<\/code> file located in your website&#8217;s root directory. Make sure to replace <code>yourdomain.com<\/code> with your actual domain and <code>newfolder<\/code> with the name of your subdirectory.<\/p>\n<pre><code>\r\nRewriteEngine on\r\nRewriteCond %{HTTP_HOST} ^(www\\.)?yourdomain\\.com$\r\nRewriteCond %{REQUEST_URI} !^\/newfolder\/\r\nRewriteCond %{REQUEST_FILENAME} !-f\r\nRewriteCond %{REQUEST_FILENAME} !-d\r\nRewriteRule ^(.*)$ \/newfolder\/$1 [L]\r\n\r\nRewriteCond %{HTTP_HOST} ^(www\\.)?yourdomain\\.com$\r\nRewriteRule ^(\/)?$ newfolder\/index.php [L]\r\n<\/code><\/pre>\n<h3>2. Understanding the Rewrite Rules<\/h3>\n<ul>\n<li><strong>RewriteEngine on<\/strong> \u2013 Enables mod_rewrite for URL redirection.<\/li>\n<li><strong>RewriteCond %{HTTP_HOST}<\/strong> \u2013 Checks if the request is coming to your domain.<\/li>\n<li><strong>RewriteCond %{REQUEST_URI} !^\/newfolder\/<\/strong> \u2013 Ensures that already redirected requests are not redirected again, preventing a loop.<\/li>\n<li><strong>RewriteCond %{REQUEST_FILENAME} !-f<\/strong> \u2013 Ensures that existing files are not affected.<\/li>\n<li><strong>RewriteCond %{REQUEST_FILENAME} !-d<\/strong> \u2013 Ensures that existing directories are not affected.<\/li>\n<li><strong>RewriteRule ^(.*)$ \/newfolder\/$1 [L]<\/strong> \u2013 Redirects all requests to the subfolder.<\/li>\n<li><strong>RewriteRule ^(\/)?$ newfolder\/index.php [L]<\/strong> \u2013 Ensures the main site loads <code>newfolder\/index.php<\/code>.<\/li>\n<\/ul>\n<h3>3. Save and Upload the .htaccess File<\/h3>\n<p>After adding the code, save your <code>.htaccess<\/code> file and upload it to your root directory. Then, clear your browser cache and test the redirection.<\/p>\n<h3>4. Need Help? @CustomerPanel Is Here for You<\/h3>\n<p>If you face issues with your redirects, reach out to <a href=\"https:\/\/customerpanel.ca\/client\">UnderHost Support<\/a>. We provide expert server management, including <a href=\"https:\/\/underhost.com\/dedicated-servers-offshore.php\">dedicated servers<\/a> and <a href=\"https:\/\/underhost.com\/cloud-vps.php\">cloud hosting<\/a>, ensuring your website runs smoothly.<\/p>\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":[11],"tags":[],"class_list":["post-3673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to"],"_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":3,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3673\/revisions"}],"predecessor-version":[{"id":5143,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3673\/revisions\/5143"}],"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}]}}