skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    Although I had enabled mod_rewrite through the terminal via the following command:

    sudo a2enmod rewrite
    

    But it was not enabled and I manually activated it from ‍/etc/apache2/apache2.conf.


  2. use it without site

    localhost/admin
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search