Apache 如何将特定URL段路由到单独的web根目录?
我的yii项目具有以下结构:Apache 如何将特定URL段路由到单独的web根目录?,apache,.htaccess,mod-rewrite,yii,Apache,.htaccess,Mod Rewrite,Yii,我的yii项目具有以下结构: webapp ----frontend --------www ------------index.php ----backend --------www ------------index.php ----api --------www ------------index.php Apache2.2 每个www目录都有自己的.htaccess文件。例如“webapp/frontend/www/.htaccess”: 对于应用程序
webapp
----frontend
--------www
------------index.php
----backend
--------www
------------index.php
----api
--------www
------------index.php
Apache2.2
每个www目录都有自己的.htaccess文件。例如“webapp/frontend/www/.htaccess”:
对于应用程序的单独部分,我使用子域“api.webapp.com”、“admin.webapp.com”(public\u html文件夹中的符号链接):
但我对api的跨域ajax请求有问题,我希望得到如下结果:
http://webapp.com -> webapp/frontend/www/index.php
http://webapp.com/api/ -> webapp/api/www/index.php
http://webapp.com/admin/ -> webapp/backend/www/index.php
将URL段路由到特定web根目录的正确方法是什么?别名、.htaccess、符号链接,可能还有其他内容?正如aCodeSmith所说,您可以正确配置
.htaccess
文件来解决此问题
的文档根应为webapp
.htaccess
文件1) 亚历克斯·阿克尔(Alex Akr)
webapp是root用户
webapp/.htaccess:
RewriteCond $1 ^api\/
RewriteRule ^(.*) api/www/index.php [L,PT]
RewriteCond $1 ^admin\/
RewriteRule ^(.*) admin/www/index.php [L,PT]
RewriteRule . frontend/www/index.php
2) webapp/frontend/www是根目录。在apache配置集别名中:
Alias /api /var/www/webapp/data/www/webapp/api/www
<Directory /var/www/webapp/data/www/webapp/api/www>
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
.htaccess和多个index.php文件最适合将整个uri段指向子文件夹。 RewriteCond $1 ^api\/ RewriteRule ^(.*) api/www/index.php [L,PT] RewriteCond $1 ^admin\/ RewriteRule ^(.*) admin/www/index.php [L,PT] RewriteRule . frontend/www/index.php
RewriteCond $1 ^api\/
RewriteRule ^(.*) api/www/index.php [L,PT]
RewriteCond $1 ^admin\/
RewriteRule ^(.*) admin/www/index.php [L,PT]
RewriteRule . frontend/www/index.php
Alias /api /var/www/webapp/data/www/webapp/api/www
<Directory /var/www/webapp/data/www/webapp/api/www>
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule ^([^/].*)$ /api/index.php/$1 [L]