Wildcard SSL Certificiates

Accessing the .htaccess file

The .htaccess file is located in the public_html folder. While you can use an FTP or SSH client to access the file, for this article we will be using the File Manger.
  1. Login to your cPanel.
  2. Click the "File Manager", located in the Files section of the cPanel.
  3. File Manager
  4. Choose to open the "Web Root (public_html/www)" Web Root
    Note: Be sure to check the box "Show Hidden Files (dotfiles)."
  5. Show Hidden Files
  6. Right click the .htaccess file and choose "Edit" or "Code Edit
You will need to copy the following text into your .htaccess file. Please pay close attention to the comments (lines starting with #) so that you can properly setup the rewrite for your subdomains.
Note:You will need to replace subdomain with your subdomain and yourmaindomain.com with your domain name.

 

# most-host.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(subdomain.)?yourmaindomain.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change yourdomain.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(subdomain.)?yourmaindomain.com$
RewriteRule ^(/)?$ subdirectory/index.php [L]

 

Once you have modified this code you may need to clear your browser cache to be able to see the redirect.
  • 64 Users Found This Useful
Was this answer helpful?

Related Articles

URL redirect/rewrite using the .htaccess file

Problem: How do I perform a URL redirect/rewrite using the .htaccess file? Solution: .htaccess...

How to host the Primary Domain from a subfolder (.htaccess)

How do I make a sub directory (or sub folder) act as the public_html for your main domain? The...

Redirects that do not work due to PHP variables

Problem: The redirection of www.yourdomain.com/default.html or index.html to...

Redirect

Problem: How do I create a redirect? Solution: The Redirects tool will allow you to redirect...

Restrict subdomain access to addon domains

Problem: How do I stop people from being able to use the addon domain as a subdomain of the...