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

2023-08-17php开发问题
5

本文介绍了Yii 2.0 从 URL 中隐藏/basic/web 以及 index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

Plenty of information around the net on how to hide the index.php from your Yii 2.0 application URL, however, what I'm trying to do here is to also remove the '/basic/web/' from the URL. /basic/web is the directory from which the application is running and the configuration that I have so far is the following. That goes into the config file:

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

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

And this is my htaccess file that I have within the /web folder:

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?

So far, so good, I can access something directly calling mysite.com/basic/web/controller/action. What do I need to do though to remove the /basic/web so that the URL becomes just simple mysite.com/controller/action?

欢迎提供任何提示,谢谢!

Any tips welcome, thanks!

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

I'm looking for a way without touching the apache configuration file as I don't have access to it.

推荐答案

您应该以另一种方式定义您的 apache 配置.您的网站应该指向 {folder}/basic/web 而不是 {folder}.

You should define your apache configuration in another way. Your site should point to {folder}/basic/web and not to {folder}.

因为你改变了要求:

对于 cpanel 设置,您应该:
1)删除愚蠢的基本文件夹,它有什么意义?仅仅因为 Yii 以这种方式安装并不意味着您必须保留它.因此,将所有内容向上移动 1 级.
2) 将 web 重命名为 public_html 确保在某些文件中也将其重命名(想到 config/bootstrap).

For a cpanel setup you should:
1) remove the silly basic folder, what is the point of it anyway? Just because Yii installs that way does not mean you have to keep it. So move everything 1 level up.
2) Rename web to public_html make sure you rename it in some files too (config/bootstrap comes to mind).

是的,您可以使用 .htaccess 来实现,但您不应将文件暴露在 Internet 上,只应暴露您的 Web 文件夹,因此我不会为您提供该解决方案,因为它不是一个好的解决方案.

Yes you can do it with .htaccess but you should not have the files exposed to the internet, just your web folder should be exposed so I am not giving you that solution because it is not a good one.

这篇关于Yii 2.0 从 URL 中隐藏/basic/web 以及 index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17