Yii2 |使用 htaccess 重定向到 backend/frontend
Yii2 | Redirect to backend/frontend with htaccess
我在 localhost
上使用 Yii2 高级模板,我想在 url 为 localhost/site/admin
时将用户重定向到 backend/web
并重定向到 frontend/web
当 url 是 localhost/site
使用 .htaccess
文件时。
我启用了 apache rewrite
并尝试了这些解决方案
advance template Yii2 - redirect to frontend/web using htaccess
Yii2 .htaccess redirect to backend part
Redirecting to backend via htaccess Yii2
但在所有情况下,当 url 为 localhost/site/admin
时,我得到 404 Error
Not Found
The requested URL /site/admin was not found on this server.
当 url 为 localhost/site
时,我的站点根目录的内容将显示给我。
现在我在项目根目录中的 .htaccess
是:
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(/.+)?$ backend/web/ [L,PT]
RewriteRule ^(.+)?$ frontend/web/
在backend/web
和frontend/web
中是:
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
尽管我通过以下命令通过终端启用了 mod_rewrite
:
sudo a2enmod rewrite
但是没有启用,我从/etc/apache2/apache2.conf
手动激活了它。
不使用 site
localhost/admin
我在 localhost
上使用 Yii2 高级模板,我想在 url 为 localhost/site/admin
时将用户重定向到 backend/web
并重定向到 frontend/web
当 url 是 localhost/site
使用 .htaccess
文件时。
我启用了 apache rewrite
并尝试了这些解决方案
advance template Yii2 - redirect to frontend/web using htaccess
Yii2 .htaccess redirect to backend part
Redirecting to backend via htaccess Yii2
但在所有情况下,当 url 为 localhost/site/admin
404 Error
Not Found
The requested URL /site/admin was not found on this server.
当 url 为 localhost/site
时,我的站点根目录的内容将显示给我。
现在我在项目根目录中的 .htaccess
是:
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(/.+)?$ backend/web/ [L,PT]
RewriteRule ^(.+)?$ frontend/web/
在backend/web
和frontend/web
中是:
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
尽管我通过以下命令通过终端启用了 mod_rewrite
:
sudo a2enmod rewrite
但是没有启用,我从/etc/apache2/apache2.conf
手动激活了它。
不使用 site
localhost/admin