使用.htaccess处理后端和前端的请求

问题描述 投票:1回答:2

首先,对于任何英文错误我深表歉意。

好吧,我的问题是这样的:

我有一个具有后端的文件夹,并在以下路径中接收请求

(which contains an index.php file that handles requests) (which contains an index.php file that handles requests)

我有一个包含前端的文件夹,并在以下路径中接收请求

(which contains an index.php file that handles requests) (which contains an index.php file that handles requests)

我还有一个名为common的文件夹,在后端和前端之间共享(包含框架的库以及其他文件)

需要的是何时访问此位置:

h**p://localhost/andre/admin

将其重写为:

h**p://localhost/andre/backend/www (当前状态)


换句话说,不是通过以下方式访问后端:

h**p://localhost/andre/backend/www

用这个地址:

h**p://localhost/andre/admin


所有其他未指向的请求:

h**p://localhost/andre/admin

通过以下方式访问:

h**p://localhost/andre/ (ie, point to h**p://localhost/andre/frontend/www)

(我希望你能理解我想要的)

我需要帮助,在使用.htaccess文件做到这一点的方式上,我无法使用符号链接或子域解决此问题...

我在Google和此处进行了很多搜索,但没有发现任何有效的方法或可以帮助我的方法。

PS:我将Yii Framework和YiiBoilerplate一起使用,但是我认为解决方案不应该存在

提前致谢!

php apache .htaccess mod-rewrite yii
2个回答
0
投票

将此代码放在/andre/.htaccess文件中

RewriteEngine On
RewriteBase /andre/

RewriteRule ^admin(/.*)?$ backend/www$1 [NC,L]

RewriteCond %{REQUEST_URI} !/(frontend|backend)/ [NC]
RewriteRule ^(.*)$ frontend/www/index.php/$1 [L]

0
投票

用以下代码解决:

RewriteEngine On
RewriteBase /andre/

RewriteRule ^admin(/.*)?$ backend/www/index.php/$1 [L,NC]

RewriteCond %{REQUEST_URI} !/(frontend|backend)/ [NC]
RewriteRule ^(.*)?$ frontend/www/index.php/$1 [L,NC]
© www.soinside.com 2019 - 2024. All rights reserved.