【问题标题】:Configuring Apache for Yii2 UrlManager's 'enablePrettyUrl' parametre on Windows在 Windows 上为 Yii2 UrlManager 的“enablePrettyUrl”参数配置 Apache
【发布时间】:2017-03-13 17:13:21
【问题描述】:

我尝试关注Yii2 Official Guide 为 enablePrettyUrl 选项配置 Apache-2.4x64。我的问题是尝试在浏览器中访问 localhost/about/web/ 时出现 500 服务器错误。我已将 .htaccess 放在我的 about/web 文件夹中。 这是它的配置:

# Set document root to be "basic/web"
DocumentRoot "d:/openserver/domains/localhost/about/web"

<Directory "d:/openserver/domains/localhost/about/web">
    # 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

    # ...other settings...
</Directory>

可能到 about/web 的路径有问题?我只在我的 Windows 机器上出现此错误。

【问题讨论】:

  • Apache 日志中有什么内容?
  • path/to/localhost/about/web/.htaccess:此处不允许 DocumentRoot,引用者:dev/about
  • 感谢您提醒我有关日志的信息。现在我明白了。

标签: php apache .htaccess server yii2


【解决方案1】:

DirectoryDocumentRoot 不允许在 .htaccess 文件中,它们应该在 apache 配置中(或在您的 VirtualHost 配置文件中)。

在您的情况下,正在读取 .htaccess 文件,这就是它给您错误 500 的原因(该文件已读取但它包含系统税错误或错误命令)。因此,删除“DirectoryandDocumentRoot”命令并保留文件就足够了:

# 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

请确保在您的 apache 安装中启用了 mod_rewrite

【讨论】:

  • 那我应该在 httpd.conf 中做同样的事情吗?
  • 只需从 .htaccess 文件中删除 DirectoryDocumentRoot 命令
猜你喜欢
  • 2017-03-14
  • 1970-01-01
  • 1970-01-01
  • 2017-08-26
  • 1970-01-01
  • 2010-09-18
  • 1970-01-01
  • 2015-11-05
  • 1970-01-01
相关资源
最近更新 更多