网络上有很多关于如何从 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/