You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 without www) and skips the validation rules you already had—don't remove these, they keep HostGator's SSL and domain verification working.
  • The !-f and !-d checks ensure we only rewrite requests for files/directories that don't exist directly in public_html. This means if you have other files in public_html (like for your otherdomain), they'll still work normally.
  • Internally, the server maps domain1.com/app/index.html to public_html/domain1/app/index.html without showing the /domain1/ path in the URL.
  • The optional redirect rule fixes any accidental visits to domain1.com/domain1/app/index.html by sending users to the clean, short URL (a 301 permanent redirect is best for SEO).

Quick checks after updating:

  1. Confirm the .htaccess is in your public_html root, not inside the domain1 folder.
  2. Visit domain1.com/app—it should load your index.html without the extra path segment.
  3. If you have other domain rules in the same .htaccess, keep them below these domain1.com rules (rewrite rules run in order).

内容的提问来源于stack exchange,提问作者Guilherme Dimarchi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:08:27