First,

my `'example.com'` domain is linked to `'/home/defaultfolder/'` folder.

I want to redirect

```
example.com , www.example.com

```

to

`/home/somefolder/example/` , not `/home/defaultfolder/` folder

by using .htaccess. (both are inside the DocumentRoot directory)

also, subdomains like

```
a.example.com

```

to

```
/somefolder/example/a/

```

but keeps the 'example.com' domain.

I have tried some examples on the web, but nothing could have done it.

How can I write the .htaccess to do so? Thank you.

Of course, I cannot change server settings(like alias virtual hosts..) and that's why I am trying to do it by modifying the file.

---

I have tried

```
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule /somefolder/example/$1 [R=301,NC,L]

RewriteCond %{HTTP_HOST} ^(www.)?example.com$   
RewriteRule !^/somefolder/example/ /somefolder/example/1%{REQUEST_URI} [L]

RewriteCond %{HTTP_HOST} ^/?(?:www\.)?example.com
RewriteRule ^(.*)$ /somefolder/example/$1 [R=permanent,L]

```

and some others..