php - Yii 2.0 从 URL 中隐藏/basic/web 以及 index.php

标签 php .htaccess yii url-rewriting yii2

网络上有很多关于如何从 Yii 2.0 应用程序 URL 中隐藏 index.php 的信息,但是,我在这里要做的是同时从 URL 中删除“/basic/web/”。/basic/web 是应用程序运行的目录,我目前的配置如下。这进入配置文件:

'urlManager' =>[
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],

这是我在/web 文件夹中的 htaccess 文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

到目前为止一切顺利,我可以直接调用 mysite.com/basic/web/controller/action 访问某些内容。我需要做什么才能删除/basic/web 以便 URL 变得简单 mysite.com/controller/action

欢迎任何提示,谢谢!

编辑:我正在寻找一种不接触 apache 配置文件的方法,因为我无权访问它。

最佳答案

RewriteEngine on
# Change yourdomain.com to be your primary domain.

RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$

RewriteCond %{REQUEST_URI} !^/basic/web/

# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /basic/web/$1

RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$ 
RewriteRule ^(/)?$ basic/web/index.php [L]

完成后将 .htaccess 权限更改为 440。与 Mihai P 所说的相反,不用担心使用此方法。

关于php - Yii 2.0 从 URL 中隐藏/basic/web 以及 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27178364/

相关文章:

php - 移动检测高流量站点

php - 重定向跳过 www 是常见的做法吗?

php - 基于 yii 中数据的 CGridView 中的样式列

php - yii 中的控制台应用程序无法包含 AR 模型

javascript - 单击按钮后重定向到应用商店或谷歌商店

php - 尝试创建 PHP 搜索脚本

.htaccess - 让 Flask 在 mod-rewrite 后面使用所需的 URL

Apache Tomcat 重写

php - Yii、yiic 和控制台

PHPExcel - 如何逐行读取 Excel 工作表