如何配置GoDaddy主机,让根目录指向public_html/production目录?
Absolutely, there are a few straightforward ways to make your site accessible at example.com/index.php instead of needing the /production subdirectory. Let’s walk through the most reliable options for GoDaddy hosting:
Option 1: Change Your Document Root (Cleanest Solution)
This is the most direct approach—you’ll tell GoDaddy to serve files directly from your production folder instead of the default public_html root. Here’s how:
- Log into your GoDaddy Hosting Control Panel.
- Navigate to your domain’s settings (look for "Manage" next to your domain, or go to "Web Hosting" > "Manage" > "Settings").
- Find the Document Root option (usually under "Domain" or "Advanced Settings").
- Update the path from
public_htmltopublic_html/productionand save changes.
Important Note:
After changing the document root, double-check the path to your database connection file in index.php. Since your site’s root is now production, you’ll need to adjust the include path to point up one directory:
// Before: // include 'includes/conection_DB.php'; // After: include '../includes/conection_DB.php';
This ensures your index.php can still find the conection_DB.php file in the public_html/includes folder.
Option 2: Use .htaccess Rewrite Rules (No Document Root Changes Needed)
If you can’t or don’t want to modify the document root, you can use an .htaccess file to silently redirect traffic from example.com/* to example.com/production/*. Here’s how:
- Create or edit the
.htaccessfile in yourpublic_htmlfolder (if it doesn’t exist, just create a new plain text file named.htaccess). - Add these lines:
RewriteEngine On RewriteCond %{REQUEST_URI} !^/production/ RewriteRule ^(.*)$ /production/$1 [L]
- Save the file and upload it to your
public_htmldirectory if you edited it locally.
How This Works:
RewriteEngine Onenables URL rewriting.RewriteCond %{REQUEST_URI} !^/production/makes sure we don’t redirect requests that already go to/production(to avoid loops).RewriteRule ^(.*)$ /production/$1 [L]takes any request toexample.com/anythingand serves the corresponding file fromexample.com/production/anything, while keeping the original URL visible.
Option 3: Move Your Files (Quick for Simple Projects)
If your production folder only has index.php and no other assets (like CSS, JS, or images), you can just move the file to the public_html root:
- Move
public_html/production/index.phptopublic_html/index.php. - Update the include path in the moved
index.phpto point directly to theincludesfolder (since it’s now in the same root asincludes):
// Before: // include '../includes/conection_DB.php'; // After: include 'includes/conection_DB.php';
Warning: If your production folder has other files (like assets), you’ll need to move those too or update all their paths in your code—this can get messy for larger projects, so we don’t recommend this unless your setup is super simple.
内容的提问来源于stack exchange,提问作者Isaac Hernández Cabrera

