0

I'm new to this community. I bought a domain that gives me the chance to manage DNS and Name Servers. In my hosting I've three folders (for instance "a", "b", "c"). I thought I'd create three third-level DNS A record (for istance "a.mydomain.com", "b.mydomain.com", "c.mydomain.com") and make each of them pointing to the same IP of my hosting. How should I configure the .htaccess file in the root of hosting folder so as to when I access to a.mydomain.com it'll access to "www.mydomain.com/a" and so on for b and c? Thank you in advance!

lucapada
  • 1
  • 1
  • Welcome to Stack Overflow! You do this with Apache's virtual hosting: https://httpd.apache.org/docs/2.4/vhosts/ One virtual host set of settings for each subdomain – Katie May 11 '20 at 11:24
  • Ok. But this is not possible in my hosting production environment :/ – lucapada May 11 '20 at 11:51
  • Instead of asking “how” questions here, you should rather do some basic research. “subdomain to folder rewrite” typed into Google leads to https://stackoverflow.com/questions/10642426/htaccess-rewrite-subdomain-to-directory in no time. – CBroe May 11 '20 at 12:00
  • @CBroe - one caveat on the solution you point to (which might be the only one possible in this situation), the URL will be changed in the browser address bar, which is a different experience for the visitor – Katie May 11 '20 at 12:14
  • @Katie this does not need to change what the address bar shows - if it is just an _internal rewrite_, instead of an external redirect, then the address bar content in the browser stays the same. – CBroe May 11 '20 at 12:16
  • @CBroe I tried also with the solution you posted. I decided to create another question because that one was not working... I created my ".htaccess" file and i write into it only these three codelines: `RewriteEngine on RewriteCond %{HTTP_HOST} ^a.mydomain.com RewriteRule ^(.*)$ /a/$1 [L,NC,QSA]` – lucapada May 11 '20 at 14:04
  • Please go read [ask]. “Not working” is not a useful problem description to begin with; you need to give us a _proper_ problem description, that explains what exactly is happening. (I’d probably expect a 500 error, due to a redirect loop, or something similar here. You might need to add an exception, so that any internal request that goes to `/a/foo` already, does not get rewritten _again_ on the next round.) – CBroe May 11 '20 at 14:13
  • Sorry. When I said "not working" I was meaning that "nothing happened". After the change I mentioned in my last comment, when I go with my browser to the subdomain, it opens me the main page of my website located at the default root and it doesn't open the page contained into the subfolder as I want. – lucapada May 11 '20 at 16:38

0 Answers0