Yii2 .htaccess重定向到后端部分

问题描述 投票:0回答:1

我已经安装了Yii2高级应用程序,我现在要做的是将此url htpp://site/admin重定向到后端(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]

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

.htaccess redirect yii2 yii2-advanced-app
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.