Question

How to have each folder within a root folder act as a subdomain?

Hello there,

I am new to DigitalOcean and new to server management. What I am trying to achieve is that, I want each of my folder in the root folder, act as a subdomain. For e.g: mywebsite.co.uk/folder1 and folder1.mywebsite.co.uk should be the same directory, mywebsite.co.uk/folder2 and folder2.mywebsite.co.uk should be same. At my old host, I just use to create folders within the root directory and then they were accessible as subdomains. I am trying to achieve the same effect. Someone was helping me with this on the chat, but then we were waiting for my dns to get updated. So far he ased me to add * in CNAME and point it to mywebsite.co.uk and put a .htaccess file in the root folder, which looks like the following;

RewriteEngine on RewriteCond %{HTTP_HOST} ^(.).mywebsite.co.uk RewriteRule ^(.)$ http://mywebsite.co.uk/%1/$1 [L,NC,QSA]

At the moment any subdomain I try, it goes to the main root directory. for example: folder1.mywesbite.co.uk, folder2.mywebsite.co.uk, blahblah.mywebsite.co.uk all goes to the index.html file in /var/www. folder1 and folder2 exists in the root but blahblah doesn’t exists.

Can someone please help me.

Regards

Salman


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

What does your does the rest of you Apache config look like?