0

我的文档根目录中有三个文件夹 -

localhost/myMainProject/   
localhost/myMainProjectSubdomain/  
localhost/myThirdProject/

我想做以下 URL 映射 -

www.mymainproject.com ---> localhost/myMainProject/
mysubdomain.mymainproject.com ---> localhost/myMainProjectSubdomain/
www.mythirdproject.com ---> localhost/myThirdProject/

我试图将我的主机文件更改为:

127.0.0.1/myMainProjectSubdomain mysubdomain.mymainproject.com
127.0.0.1/myMainProject www.mymainproject.com 
127.0.0.1/myThirdProject www.mythirdproject.com

但这不起作用。我想我必须在某个地方创建一些 .htaccess 文件或其他东西,但不知道它是如何工作的。

这可能吗 ?请指导我如何实现这一目标。谢谢。

4

2 回答 2

2

将其放入文档根目录中的 htaccess 文件中:

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]
于 2012-08-09T03:09:48.900 回答
0

最后我是如何让它工作的:

在主机文件中 -

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

于 2012-08-09T03:59:29.570 回答