最后我是如何让它工作的:
在主机文件中 -
127.0.0.1 mysubdomain.mymainproject.com
127.0.0.1 www.mymainproject.com
127.0.0.1 mymainproject.com
127.0.0.1 www.mythirdproject.com
127.0.0.1 mythirdproject.com
在文档根目录中 - (如接受的答案中所述)
RewriteEngine On
# for www.mymainproject.com
RewriteCond %{HTTP_HOST} ^(www\.)?mymainproject\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/myMainProject
RewriteRule ^(.*)$ /myMainProject/$1 [L]
# for mysubdomain.mymainproject.com
RewriteCond %{HTTP_HOST} ^mysubdomain.mymainproject\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/myMainProjectSubdomain
RewriteRule ^(.*)$ /myMainProjectSubdomain/$1 [L]
# for www.mythirdproject.com
RewriteCond %{HTTP_HOST} ^(www\.)?mythirdproject\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/myThirdProject
RewriteRule ^(.*)$ /myThirdProject/$1 [L]
在我的项目文件夹中,我必须创建另一个 .htaccess 文件 -
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt|images|stylesheets|javascript|captcha|js|css|table-images)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
现在 URL 映射完美!例如。
www.mymainproject.com/welcome --> localhost/myMainProject/welcome