Yii2 .htaccess重定向到后端部分

时间:2017-12-20 18:38:28

标签: .htaccess redirect yii2 yii2-advanced-app

我已经安装了Yii2高级应用,我现在要做的是将此网址htpp://site/admin重定向到后端(管理员)端。到目前为止我尝试的是:

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]

我不熟悉whit .htaccess,我不确定什么是正确的方法。这个代码是我在谷歌上搜索后发现的。 .htaccess文件位于app/backend/web/.htaccess。你能用正确的方式指出我吗?提前谢谢!

1 个答案:

答案 0 :(得分:0)

简单:

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