【发布时间】:2019-07-17 12:45:14
【问题描述】:
我负责将另一个人开发的 yii 项目,在服务器 (A) 上工作到另一台服务器 (B)。在B服务器中,必须保留的网站已经在/var/www/html/site中使用apache运行
该应用是具有 REST API 的网站。该网站的链接是 www.domain.com/max (located in /var/www/html/max) 和 api 的链接是:www.domain.com/max/apiV1 ( located in /var/www/html/max/protected/apiV1 我想)..
我试图复制/粘贴网站的文件夹并访问它:它可以工作,但是当我尝试使用默认路径以外的其他路径时,它会为所有内容返回“未找到”。
这里是配置文件的摘录:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'login'=>'site/login',
'logout'=>'site/logout',
'about'=>'site/about',
'how-it-works'=>'site/howitworks',
'our-offers'=>'site/ouroffers',
'contact'=>'site/contact',
'join'=>'site/register',
),
),
还有一个 SiteController 摘录显示登录路由应该可以工作,不是吗?
public function actionLogin()
{
...
}
另外,我没有看到任何与 API 相关的内容(这是 yii 项目的一个模块)。所以我不明白 A 服务器如何通过 www.domain.com 访问某些内容/apiV1
我希望能够请求 API 并完全访问网站。
我希望我的解释足够明确,不要犹豫,询问有关该项目的更多信息!
感谢阅读! 我真的希望我们能够找到解决方案
编辑: Apache 配置文件
是的
在 A 服务器中,apache 配置“000-default”是:
DocumentRoot "/var/www/html/max"
<Directory "/var/www/html/max/">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
</Directory>
并在 B 中为文件“max.conf”
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/max
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =maxtouch-app.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteRule ^index.php/ - [L,R=404]
编辑2:项目的.htaccess文件
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
【问题讨论】:
-
你检查之前的 apache/nginx 配置了吗?
-
<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',将它们移到列表的末尾 -
是的,我检查了它们。我编辑了问题添加了apache配置文件@delboy1978uk
-
@MuhammadOmerAslam:聪明的主意!但它不起作用
-
好的,您可以在不使用漂亮网址的情况下访问路线吗?使用
index.php?r=controller/action
标签: php yii configuration project transfer