I am using Yii2 advanced template on localhost
and I want to redirect the user to backend/web
when the url is localhost/site/admin
and redirect to frontend/web
when the url is localhost/site
using .htaccess
file.
I enabled apache rewrite
and I have tried these solutions
advance template Yii2 - redirect to frontend/web using htaccess
Yii2 .htaccess redirect to backend part
Redirecting to backend via htaccess Yii2
but in all cases I get 404 Error
when the url is localhost/site/admin
Not Found
The requested URL /site/admin was not found on this server.
and when the url is localhost/site
the content of the root directory of my site is displayed to me.
Now my .htaccess
in the root of project is :
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(/.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.+)?$ frontend/web/$1
and in backend/web
and frontend/web
is:
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
RewriteRule ^(.+)admin(/.+)?$ backend/web/$1 [L,PT]
should work. I think you are matching forlocalhost/admin
with the above rule. Please, let me know how it goes. - Martin Dimitrov.htaccess
see here - Muhammad Omer Aslammod_rewrite
enabled through the terminal, there was no change in the configuration file and I made the changes manually. - Hamedsymlink
or the front and backend or follow this github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/… - Muhammad Omer Aslam