从一个服务器向另一个服务器传输Yii项目时出现问题(路由问题)

wz3gfoph  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(160)

我负责把一个别人开发的yii项目,从A服务器转移到B服务器上,B服务器上有一个必须保留的网站已经在/var/www/html/site的apache上运行了
应用程序是具有REST API的网站。指向网站的链接是www.domain.com/maxlocated in /var/www/html/max),指向API的链接是:(我想是的)
我试图复制/粘贴网站的文件夹和访问它:它工作,但当我试图去其他路线,而不是默认的一个,它返回一个“未找到”的一切。
下面是配置文件的摘录:

'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/apiV 1的东西
我希望能够请求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
wgx48brx

wgx48brx1#

作为,您说您可以访问默认路由,即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

此外,在您的项目配置中,您需要在所有规则之前添加max/,以便为项目位置配置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', 
        ),
),

希望对你有帮助。

相关问题