Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map subdomain to folder on the server?

Under the /public_html/ folder, on domain.com, there's a folder named shops. Within that folder, there are multiple sub-folders, each with its own index file, css, js etc. For example, there could be one named flowerstore.

I need to have URLs such as shop.domain.com/flowerstore point to /public_html/shops/flowerstore, using the .htaccess.

My current rewrite directives don't seem to work, so I could really use your help.

RewriteCond %{HTTP_HOST} ^shop\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/shops/
RewriteRule (.*) /shops/$1

If it makes any difference, my site is hosted with GoDaddy, but we're using AWS' DNS. Pretty sure it won't make any difference, but rather it's an htaccess quirk.

like image 244
Andrei Oniga Avatar asked Jul 04 '15 19:07

Andrei Oniga


2 Answers

Your rules work fine for me. I have tested them on my server.

domain.com -> domain.com/

shop.domain.com -> shop.domain.com/shops/

shop.domain.com/flowershop -> shop.domain.com/shops/flowershop/

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^shop\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/shops/
RewriteRule (.*) /shops/$1

I'm not sure how it works on GoDaddy, but you may just need to turn the rewrite engine on as I have in the above.

like image 126
Jacob Margason Avatar answered Sep 28 '22 03:09

Jacob Margason


You can achieve this without configuring your .htaccess file. Did you create your shop.domain.com using the Subdomains app? If not, you can then follow these steps:

  1. Log in to your domain name registrar and point the DNS record of shop.domain.com to the IP address of your server. Note that DNS can take up to 48 hours to propagate. Visit Managing a Domain Name's Subdomains | GoDaddy Help for more info about your web host.
  2. Log in your web hosting account and go to the Subdomains, you can find that app in the Domains section of your control panel.
  3. Create a Subdomain "shop.domain.com" with "/public_html/shops" Document Root.
  4. Then that's it, just wait until the DNS propagate and your shop.domain.com/flowerstore is now pointed to /public_html/shops/flowerstore. Just tweak some other URLs if necessary.

If you created the subdomain using the Subdomains app, you can simply modify its document root also in that area and set it to "/public_html/shops".

like image 45
5ervant - techintel.github.io Avatar answered Sep 28 '22 01:09

5ervant - techintel.github.io