网上有很多关于如何从 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!