【发布时间】:2013-07-31 13:00:20
【问题描述】:
我的 yii 项目结构如下:
webapp
----frontend
--------www
------------index.php
----backend
--------www
------------index.php
----api
--------www
------------index.php
https://github.com/tonydspaniard/yiinitializr-advanced
阿帕奇 2.2
每个 www 目录都有自己的 .htaccess 文件。例如“webapp/frontend/www/.htaccess”:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/].*)$ /index.php/$1 [L]
对于应用程序的不同部分,我使用子域“api.webapp.com”、“admin.webapp.com”(public_html 文件夹中的符号链接):
webapp.com -> webapp/frontend/www
api.webapp.com -> webapp/api/www
admin.webapp.com -> webapp/backend/www
但是我对 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、符号链接,也许还有别的?
【问题讨论】:
-
.htaccess 和多个 index.php 文件最适合将整个 uri 段指向子文件夹。
标签: apache .htaccess mod-rewrite yii