2017-09-24 61 views
0

我试图在一个Share Hosting环境中部署Yii2(基本模板)的小型项目。一切都在当地正常工作。 主机服务器就像下面的根目录:Yii2 Pretty Url在Share Hosting(基本模板)中不起作用

/ 
---logs 
---index.html 

阅读Yii2的doc后。然后删除文件index.html并将我的项目文件夹上传到根目录。它现在看起来像这样:

/ 
---logs 
---assets 
---commands 
---config 
---controllers 
--- ... 
---views 
---web 
--- ... 

尝试网站后,我有一个空白页。于是我决定创建主机服务器的根目录htaccess文件指向网络文件夹喜欢这里

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^www.example.com$ 
RewriteCond %{REQUEST_URI} !web/ 
RewriteRule (.*) /web/$1 [L] 

在这之后我能得到的索引页非常好,

www.example.com 

当我尝试访问例如(与URL prettyUrl激活)时,我得到空白页

www.example.com/articles/list 

,但是当我停用prettyUrl,它那像工作例如

www.example.com/web/index.php?r=articles/list 

在Web文件夹中的.htaccess是这样的:

Options +FollowSymLinks 
IndexIgnore */* 

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 

# Disable Directory Browsing 
Options All -Indexes 

和URL规则在web.php设置文件如下:

'urlManager' => [ 
     'class' => 'yii\web\UrlManager', 
     'showScriptName' => false, 
     'enablePrettyUrl' => true, 
     'baseUrl' => '/', 
     'rules' => [       
       ... 
       '<controller:\w+>/<id:\d+>' => '<controller>/view', 
       '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', 
       '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 

       ], 
    ], 
+0

我要做的第一件事就是在'.htaccess'文件中引入一些垃圾来检查它是否被读取。如果是这样,访问任何页面时应该弹出一个错误500 – gmc

+0

@gmc我做了它并且读取了.htaccess文件。 – stfsngue

回答

0

大多数共享主机禁用了一些来自htaccess文件的指令以防止一些安全问题。如果在你的htaccess文件中发现一个受限制的指令,你会得到一个500错误页面。

很可能如果您删除Options +FollowSymLinks指令,一切都会生效。

此外,您可以查看apache错误日志以获取更多信息。

+0

感谢您的帮助。但它仍然不起作用。 – stfsngue

+0

你在apache错误日志中有一些错误吗? Ps .:尝试从配置中删除baseUrl。 –