简体   繁体   中英

Yii2: Hiding frontend/web and backend/web from UrlManger

I managed to hide frontend/web and backend/web/ using .htaccess file. But the urlManager unable to understand that. I'm trying to create url like site/index and it should be something like this: example.com/site/index but it creates example.com/frontend/web/site/index .

How do I solve this problem with UrlManager ?

Update: .htaccess in root directory.

Options -Indexes
RewriteEngine on

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
RewriteCond %{REQUEST_URI} admin
RewriteRule .* backend/web/index.php [L]

RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !admin
RewriteRule .* frontend/web/index.php [L]
</IfModule>

and here is the one I used in both frontend/web and backend/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

I use this .htaccess config and it works fine for me. You need only one .htaccess file in your site root directory, and set frontend / backend configuration as described. Maybe this will work for you too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM