Yii2 .htaccess redirect to backend part

安稳与你 提交于 2019-12-13 03:50:54

问题


I have installed Yii2 advanced app and what i am trying to do now is to redirect this url htpp://site/admin to the backend ( admin ) side. What i tried so far is:

AddDefaultCharset utf-8

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on


# Make the backend accessible via url: http://site/admin
RewriteRule ^admin$ $admin.php [L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php


RewriteRule ^static - [L]

I am not familiar whit .htaccess and i am not pretty sure what is the right way. This code is what i found after googling. The .htaccess file is in the app/backend/web/.htaccess. Can you point me the right way? Thank you in advance!


回答1:


easy :

RewriteEngine On

# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend)/web/ - [L]

# Handle the case of backend, skip ([S=1]) the following rule, if current matched
RewriteRule ^admin(/(.*))?$ backend/web/$2 [S=1]

# handle the case of frontend
RewriteRule .* frontend/web/$0

# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php


来源:https://stackoverflow.com/questions/47912419/yii2-htaccess-redirect-to-backend-part

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!