How to set Primary Domain to subfolder by .htaccess

How to set primary domain to subfolder by .htaccess?

  1. Have a domain. In example is wpcodewriter.com
  2. Creat folder wpcodewriter.com (your-domain) in public_html
  3. Creat file .htaccess in public_html with below code
    # Do not change this line.
    RewriteEngine on
    # Change yourdomain.com to be your main domain.
    RewriteCond %{HTTP_HOST} ^(www.)?wpcodewriter.com$
    
    # Change 'subfolder' to be the folder you will use for your main domain.
    RewriteCond %{REQUEST_URI} !^/wpcodewriter.com/
    
    # Don't change this line.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # Change 'subfolder' to be the folder you will use for your main domain.
    RewriteRule ^(.*)$ /wpcodewriter.com/$1
    
    # Change yourdomain.com to be your main domain again.
    # Change 'subfolder' to be the folder you will use for your main domain
    # followed by / then the main file for your site, index.php, index.html, etc.
    
    RewriteCond %{HTTP_HOST} ^(www.)?wpcodewriter.com$
    RewriteRule ^(/)?$ wpcodewriter.com/index.html [L]
  4. Remember replace all wpcodewriter.com to your-domain (Step 2)
  5. Done!

Goodluck for you!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.