我正在尝试在yii2基本模板中设置Url Manager。以下是找到.htaccess
mysite.loc/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
在我的web.php
文件中我添加了此代码段:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
],
当我尝试输入时(例如)mysite.loc/index.php/site/movies
这样会出现错误:404 not found error nginx
如果有人知道请与我分享。我的设置有什么问题???
答案 0 :(得分:1)
我的配置
的.htaccess
@model IEnumerable<Sample.Models.TypeModel>
@foreach (var item in Model)
{
<tr>
<td>
@*if Item in model is T generate text box, if C generate text..*@
</td>
</tr>
}
配置/ web.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
尝试上述内容并转到网址'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
答案 1 :(得分:0)
我已阅读了几个主题并找到了正确的答案。在设置urlManager时,apache配置和nginx配置之间存在差异。
如果你的服务器是Apache(正如维塔利所说):
.htaccess:
open(F,"/home/file.txt")||die "error";
my $string;
while($ligne = <F> ) {
my @val = split(/ /, $ligne);
my $long=$#val;
for($i=0; $i<$long;$i+=3){
$string="$val[$i] $val[$i+1] $val[$i+2] $val[$i+3] $val[$i+4] $val[$i+5] $val[$i+6] $val[$i+7] $val[$i+8] $val[$i+9] $val[$i+10] $val[$i+11] $val[$i+12] $val[$i+13] $val[$i+14] $val[$i+15] $val[$i+16] $val[$i+17] $val[$i+18] $val[$i+19] $val[$i+20]";
my @val2 = split(/ /, $string);
my $long2=$#val2;
if($long2 >19){ #if length superior at 19, (3*7)
print FILEOUT "$string\n";
$string="";
}
}
}
config / web.php:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
如果您的服务器是Nginx:
nginx congfig文件(在我的案例中为/etc/ngnix/site-enabled/mysite.loc):
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
}
正如您所看到的,我已经添加了这段代码,仅此而已:
server {
listen 80;
root /var/www/html/mysite.loc/web;
server_name mysite.loc www.mysite.loc;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
config / web.php文件与Apache服务器相同:
location / {
try_files $uri $uri/ /index.php?$args;
}