Hi folks,

I've recently got into doing a bit of web development and got hosting for it.

The website is consisted of mainly 3 separate folders(one for home page, 2 for 2subdomains) under the html root directory to avoid cluttering.
To get to my home page on my main domain, I used to do a redirect via a html meta refresh, so i would have an index.html file under the root directory which then redirects into the 'homePage' folder. I have since learnt that this is ugly and not a recommended way to do so.

At the moment I have a ".htaccess" file under the main directory with the following line inside.

Redirect 301 /index.html http://www.mydomain.com/homepagefolder

This works very well when I type in "www.mydomain.com", it will just redirect the client to "www.mydomain.com/homepagefolder". But when I tried to access a subdomain (e.g. "subdomain.mydomain.com"). The client would also get redirected to "www.mydomain.com/homepagefolder".

I would like to know the correct way of doing the redirecting, or if there is a better way to achieve what I'm trying to do. I'm very new to web hosting and web development so any help is appreciated!

Cheers

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?myDomain.com$
RewriteCond %{REQUEST_URL} !^/folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [R=301]
RewriteCond %{HTTP_HOST} ^(www.)?myDomain$
RewriteRule ^(/)?$ folder/index.html [L]

I ended up doing this, and have it working now. (found the code from here). The code produces 2 temporary redirect rules. I've added a flag for the first one to make it a permenant redirect, but I couldnt do it for the second one. I'm not sure how that will affect SEO...

Look at this code and used it:

The code in the article through the link you provided is for directory a link request for a subdomain to a sub-directory (if I understood correctly) which was already working for me. What i needed was a way to redirect my domain to a sub-directory instead of under root, without redirecting my subdomains into the domain as well.

Member Avatar for LastMitch

What i needed was a way to redirect my domain to a sub-directory instead of under root, without redirecting my subdomains into the domain as well.

A sub-directory is in a folder. To redirect the domain to the sub-directory you just do the opposite. I have a website and also a sub-directory. To redirect I used the same code that I provided above.

But as long you got an answer on your own then everything is good because you found an answer to your issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.