Htaccess Yii 2配置

时间:2014-07-26 18:50:51

标签: apache .htaccess mod-rewrite yii2

我正在开发Yii2项目,并已在Wamp Localhost上进行设置。我的Wamp我设置了一个别名:

Alias /project "c:/Users/Shaun/Desktop/projects/project/web/" 

<Directory "c:/Users/Shaun/Desktop/projects/project/web/">
    AllowOverride all
</Directory>

在基本应用程序中,我已将hta​​ccess文件放入web目录(当前指向的位置)

  

项目/网络/ htaccess的

     

项目/网络/ index.php的

     

项目/网络/索引test.php的

mod_rewrite肯定已启用我已检查过。我可以毫无问题地导航到我的根目录:

这是我在yii2文档中演示的htaccess文件。

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


http://localhost/project/

当我导航到上面的url时,我点击了SiteController Index操作。但是当我试图去做例如:

http://localhost/project/site/index

它声明:

  

在此服务器上找不到请求的网址/Users/Shaun/Desktop/projects/project/web/index.php。

但它绝对存在?!如果您将我的web.php配置视为我已启用的组件:

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

仍然无法找到它。但如果我这样做,它显示路线很好:

http://localhost/project/index.php/site/index

因为我不想要这个令人沮丧。这是什么交易?

谢谢,

4 个答案:

答案 0 :(得分:3)

因为您正在处理虚拟目录(例如Alias / site /&#34; / dir /&#34;),您必须使用

RewriteBase /site/

在您的apache配置文件中。

答案 1 :(得分:0)

您项目的结构似乎有点不合时宜。 文件夹web中是否有另一个项目文件夹?

如果答案是肯定的,则必须将.htaccess文件放在此项目文件夹中。

但是如果项目文件夹包含网页,那就非常不合适了。但在这种情况下,.htaccess文件必须位于项目文件夹中。

答案 2 :(得分:0)

在httpd.conf或vhost conf中设置NULL 这是必须使用漂亮的URL。

答案 3 :(得分:-1)

您必须更改三个文件 基本&gt;的.htaccess
基本&gt;网络&gt;的.htaccess
基本&gt; config&gt; web.php

使用以下网址中给出的代码。

http://www.codematrics.com/htaccess-in-yii2-basic-app/

这会对你有帮助。