在Windows上为Yii2 UrlManager的'enablePrettyUrl'参数配置Apache

时间:2017-03-13 17:13:21

标签: php apache .htaccess server yii2

我尝试按照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>

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

1 个答案:

答案 0 :(得分:2)

.htaccess文件中不允许

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

在你的情况下,正在读取.htaccess文件,这就是为什么它会给你一个错误500(文件被读取但它包含systax错误或错误的命令)。因此,删除目录and DocumentRoot`命令并将文件保留为以下内容应该足够了:

# 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