我的文档根目录中有三个文件夹 -
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文件,但不知道它是如何工作的。
这可能吗?请指导我如何实现这一目标。感谢。
答案 0 :(得分: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]
答案 1 :(得分: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]
现在网址映射完美!! 例如。
www.mymainproject.com/welcome - >本地主机/ myMainProject /欢迎