HostGator主域名未放public_html根目录时的短URL配置求助
Got it, let's fix this without moving your domain1 folder out of public_html. The issue with your current .htaccess is that it's rewriting requests to a /domain1.com/ directory (which doesn't exist—your actual folder is named domain1), and that's why you're seeing the extra domain1.com/ segment in your URL. Here's how to adjust the configuration:
Updated .htaccess (place in your public_html root)
RewriteEngine On # Handle domain1.com requests RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC] # Keep these to avoid breaking HostGator's SSL/DCV validation checks RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ # Prevent rewrite loops by skipping requests already targeting the domain1 folder RewriteCond %{REQUEST_URI} !^/domain1/ # Only rewrite if the requested file/directory doesn't exist in public_html root RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /domain1/$1 [L] # Optional: Clean up URLs by redirecting direct /domain1/ access to root RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC] RewriteRule ^domain1/(.*)$ /$1 [R=301,L]
What each part does:
- The first block targets
domain1.com(with or withoutwww) and skips the validation rules you already had—don't remove these, they keep HostGator's SSL and domain verification working. - The
!-fand!-dchecks ensure we only rewrite requests for files/directories that don't exist directly inpublic_html. This means if you have other files inpublic_html(like for yourotherdomain), they'll still work normally. - Internally, the server maps
domain1.com/app/index.htmltopublic_html/domain1/app/index.htmlwithout showing the/domain1/path in the URL. - The optional redirect rule fixes any accidental visits to
domain1.com/domain1/app/index.htmlby sending users to the clean, short URL (a 301 permanent redirect is best for SEO).
Quick checks after updating:
- Confirm the
.htaccessis in yourpublic_htmlroot, not inside thedomain1folder. - Visit
domain1.com/app—it should load yourindex.htmlwithout the extra path segment. - If you have other domain rules in the same
.htaccess, keep them below thesedomain1.comrules (rewrite rules run in order).
内容的提问来源于stack exchange,提问作者Guilherme Dimarchi
相关产品推荐
相关产品推荐

