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

如何将子文件夹设为主域名根目录且访问时不显示子文件夹路径

Pointing Your Main Domain to a Subfolder

Hey there! I’ve helped a bunch of folks with exactly this issue—let’s get your www.simple.com pointing straight to Public_html/test1 instead of the root folder. Here are two common, reliable methods depending on your hosting setup:

Method 1: Using .htaccess (Shared Hosting Friendly)

This is the go-to approach if you’re on a shared host where you don’t have access to server configuration files.

  1. Locate or create the .htaccess file in your Public_html directory. If it doesn’t exist, just create a new plain text file named .htaccess (make sure the dot at the start is included!).
  2. Add the following rewrite rules to the file:
    RewriteEngine On
    # Match your main domain
    RewriteCond %{HTTP_HOST} ^www\.simple\.com$ [NC]
    # Skip requests that are already going to test1
    RewriteCond %{REQUEST_URI} !^/test1/
    # Forward all other requests to the test1 folder
    RewriteRule ^(.*)$ /test1/$1 [L]
    
  3. Save the file and test it out—visit www.simple.com and it should load content from test1 now.

Quick Notes for .htaccess:

  • If you use HTTPS, make sure this rule works for both HTTP and HTTPS (most hosts redirect HTTP to HTTPS automatically, but if not, you can adjust the rules to cover both).
  • Double-check that your host allows mod_rewrite (most do, but if you get errors, reach out to their support).

Method 2: Modifying Virtual Host Configuration (VPS/Dedicated Server)

If you have full access to your server (like a VPS or dedicated server), updating the virtual host config is a more permanent solution.

For Apache:

  1. Find your virtual host configuration file—it’s usually in /etc/apache2/sites-available/ (Ubuntu/Debian) or /etc/httpd/conf.d/ (CentOS/RHEL). Look for a file named something like simple.com.conf.
  2. Update the DocumentRoot and Directory directives to point to your test1 folder:
    <VirtualHost *:80>
        ServerName www.simple.com
        # Change this path to your actual Public_html/test1 location
        DocumentRoot /var/www/html/Public_html/test1
    
        <Directory /var/www/html/Public_html/test1>
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    
  3. If you use HTTPS, repeat the same change in the <VirtualHost *:443> block of your config.
  4. Restart Apache to apply the changes:
    # Ubuntu/Debian
    sudo systemctl restart apache2
    
    # CentOS/RHEL
    sudo systemctl restart httpd
    

For Nginx:

If you’re using Nginx instead of Apache, update your server block:

server {
    listen 80;
    server_name www.simple.com;
    root /var/www/html/Public_html/test1; # Point to your test1 folder
    index index.html index.php; # Adjust based on your site's file types

    location / {
        try_files $uri $uri/ =404;
    }
}

Then restart Nginx:

sudo systemctl restart nginx

Final Checks

  • Permissions: Make sure the test1 folder has permissions set to 755 and files to 644 (this ensures the web server can read them).
  • Cache: Clear your browser cache or use incognito mode to test the change—sometimes old cache can make it seem like the change didn’t work.

If you run into any issues (like 404 errors or permission warnings), feel free to share more details and I’ll help troubleshoot!

内容的提问来源于stack exchange,提问作者Shakib Rahman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:43:48