【发布时间】:2018-06-29 20:16:26
【问题描述】:
我正在尝试通过 htaccess 将我的 url 重定向到 domain/admin 上的管理员(后端)部分。仍然不是很熟悉.htaccess,到目前为止我所做的是
根目录主.htaccess:
#adding the charset
AddDefaultCharset utf-8
#hide the structure
Options -Indexes
#if dir is symbol, follow it
Options FollowSymlinks
#engine on
RewriteEngine
#if there is admin word in the URI go on the next rule
RewriteCond %{REQUEST_URI} ^/admin$
#load the backend index file, append the group to the url (QSA) and stop rewriting (L)
RewriteRule ^admin(/.+)$ /backend/web/$1 [QSA,L]
#everything different from admin ( because of the previous rule ) go on the next rule
RewriteCond %{REQUEST_URI} ^(.*)$
#load the frontend index file append the group to the url (QSA) and stop rewriting (L)
RewriteRule ^(.*)$ /frontend/web/$1 [QSA,L]
这是我的后端/前端.htaccess(它们是一样的):
AddDefaultCharset utf-8
RewriteEngine on
# 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
前端还可以,例如 domain/site/about 可以说,但后端 domain\admin 提供 404 not found。我理解我写的正确吗?我的错误在哪里?提前谢谢!
【问题讨论】:
标签: php .htaccess redirect mod-rewrite yii2