【发布时间】:2018-06-02 18:03:31
【问题描述】:
让我进入正题。
我有一个具有这种结构的 php 项目
ROOT
.htaccess
--api/
----public/
------index.php
------test.html
--backoffice/
而我想要的是使用 api/public 的 index.php 让它像
domain.com/api/index.php
而不是
domain.com/api/public/index.php
我一直在尝试 .htaccess 的 rewritebase 或 rewriterules 没有成功,我错过了什么?将.htaccess 放在错误的目录中?我必须使用多个 .htaccess?
更新:所以我得到了我的两个 .htaccess 文件,现在我可以使用 url domain.com/api/index.php 进行访问,但它会抛出 401 ,这是什么.. . 另一方面,我可以使用当前 url domain.com/api/test.html 访问位于 /api/public 下的文件 test.html
这里是 .htaccess
domain.com/api/.htaccess 文件
RewriteEngine On
RewriteBase /api/public/
RewriteCond %{REQUEST_URI} !^/api/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /api/public/$1
domain.com/api/public/.htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
【问题讨论】:
标签: php apache .htaccess mod-rewrite