【问题标题】:urlManager removing index.php in yii2 doesn't workurlManager 在 yii2 中删除 index.php 不起作用
【发布时间】:2015-12-18 13:54:22
【问题描述】:

我从 composer 安装了 yii2,想删除 index.php。

我试过这样做:

在配置->web.php:

    'urlManager' => [

        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
        ],
    ],

在 web->.htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

我什至通过运行deny from all 来检查 .htaccess 文件是否有效,并且它有效,但这个脚本没有,或者至少我不知道为什么。

我注意到的一些东西:

  1. 当我启用'showScriptName' => false,时,页面的页脚不显示

  2. 当我尝试打开 midori.dev/web/site/index 时,它显示:

    找不到对象!

    在此服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。

    如果您认为这是服务器错误,请联系网站管理员。

    错误 404

    midori.dev.lv Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.19

ps。我已经为midori.dev而不是localhost配置了hosts文件和vhost文件。

问题出在哪里?

【问题讨论】:

  • 为什么在 url 中包含web?试试midori.dev/site/index
  • 因为默认安装后它是网站 url 的一部分。在此之后我会尝试改变。
  • 您在哪里看到这是网站网址的一部分? web 它只是带有入口脚本 index.php 的 Web 可访问文件夹。
  • 如果我不输入 ...web/... 我根本无法得到任何结果。
  • 在这种情况下屏幕上会出现什么?

标签: yii2


【解决方案1】:

试试这个:

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

【讨论】:

    【解决方案2】:

    如果你使用的是 linux

    更改 httpd.conf 文件

    允许全部覆盖

    如果你创建一个虚拟主机, 你的文件应该是这样的

    DocumentRoot "/path/to/web"

    重写引擎开启

    # 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
    
    # ...other settings...
    

    【讨论】:

    • 我使用的是 Windows 8,但我也这样做了。
    猜你喜欢
    • 2011-08-03
    • 2014-08-12
    • 2013-12-29
    • 2019-01-14
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多