简体   繁体   中英

redirecting a domain name into a directory

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 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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM