Using URL rewrite to point a sub-domain to a sub-directory (For Linux Hosting Only)
Step 1: Create a .htaccess file with the file manager inside the public_html folder of your website. Step 2: Add your desired sample to the .htaccess file.
Manual redirection for all domains and sub-domains This .htaccess file sample will direct all domain names and sub domains to folder names that you specify.
- Use this sample if you have multiple domain names that you want to direct to the same folder.
- Use this sample if you want to direct your domains to folders with names other than mydomain.com and subdomain.mydomain.com
- You will need to make a separate entry for each of your domains in your .htaccess file
RewriteEngine on
#Fix missing trailing slash character on folders. RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]
#www.domain.com and domain.com will map to the folder {root}/folder1/ RewriteCond %{HTTP:Host} ^(?:www\.)?domain\.com$ RewriteCond %{REQUEST_URI} !^/folder1/ RewriteRule ^(.*) folder1/$1 [NC,L,NS]
#www.otherdomain.com and otherdomain.com will map to the folder {root}/folder2/ RewriteCond %{HTTP:Host} ^(?:www\.)?otherdomain\.com$ RewriteCond %{REQUEST_URI} !^/folder2/ RewriteRule ^(.*) folder2/$1 [NC,L,NS]
#subdomain.domain.com will map to the folder {root}/folder3/ RewriteCond %{HTTP:Host} ^(?:subdomain\.domain\.com)?$ RewriteCond %{REQUEST_URI} !^/folder3/ RewriteRule ^(.*) folder3/$1 [NC,L,NS]
Also See
|