将域名重定向到目录

I have a domain name directing to a www directory on the server. I have a project in the directory, so I can access the project by domainname.com/projectname/. Is there anyway to direct domainname.com directly into the project name without having to add the /projectname and behave the same thought the application? I'm using PHP.

You can use something like this

# handle domain root and skip subfolders
RewriteCond %{HTTP_HOST} www.domain.com
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_URI} \..+$
RewriteRule ^(.*)$ subfolder/$1 [L]

# add trailing slash to subfolders (eg abc to: abc/)
RewriteCond %{HTTP_HOST} www.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1/ [L,R=301]

# handle files in subfolders
RewriteCond %{HTTP_HOST} www.domain.com
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteRule ^(.*)$ subfolder/$1/ [L]

you can put this inside index.html inside domainname.com

<meta http-equiv="refresh" content="2;url=http://domainname.com/projectname/">

it will be automatically redirected to projectname subfolder