【问题标题】:Issue while transfering a yii project from a server to another one (routing issue)将 yii 项目从服务器转移到另一个服务器时出现问题(路由问题)
【发布时间】: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 配置了吗?
  • &lt;controller:\w+&gt;/&lt;id:\d+&gt;'=&gt;'&lt;controller&gt;/view', '&lt;controller:\w+&gt;/&lt;action:\w+&gt;/&lt;id:\d+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;', '&lt;controller:\w+&gt;/&lt;action:\w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;', 将它们移到列表的末尾
  • 是的,我检查了它们。我编辑了问题添加了apache配置文件@delboy1978uk
  • @MuhammadOmerAslam:聪明的主意!但它不起作用
  • 好的,您可以在不使用漂亮网址的情况下访问路线吗?使用index.php?r=controller/action

标签: php yii configuration project transfer


【解决方案1】:

如您所说,您可以访问默认路由,即 www.domain.com/max,但无法访问更多路由。问题可能是您的服务器未能将 www.domain.com/max/some/other/path 之类的 url 指向 /var/www/html/max文件夹。为此,您位于 /var/www/html/.htaccess 应该具有类似 RewriteRule ^max max/index.php 的重写规则。因此,您的 .htaccess 看起来像这样。

RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# if url has max in the start of path then point to to max folder
RewriteRule ^max max/index.php

# otherwise forward it to index.php
RewriteRule . index.php

此外,在您的项目配置中,您需要在所有规则之前添加 ma​​x/ 来为您的项目位置配置 urlManager。它看起来像这样

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName' => false,
    'rules'=>array(
        'max/<controller:\w+>/<id:\d+>'=>'<controller>/view',
        'max/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        'max/<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        'max/login'=>'site/login',
        'max/logout'=>'site/logout',
        'max/about'=>'site/about',
        'max/how-it-works'=>'site/howitworks',
        'max/our-offers'=>'site/ouroffers',
        'max/contact'=>'site/contact',
        'max/join'=>'site/register', 
        ),
),

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多