无需在 Yii 上写入索引.php



我已经在我的 WAMP 环境中设置 Yii 1.1.x,它都可以工作,但我仍然需要在 URL 中使用 index.php 才能使路由工作。

在我的 WAMP 配置中启用了模组重写。

谁能解释我需要更改什么才能允许我在 URL 本身中没有索引.php的情况下运行应用程序?

我的 Yii 配置如下:

// uncomment the following to enable URLs in path-format        
urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
            '<controller:w+>/<id:d+>'=>'<controller>/view',
            '<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>',
            '<controller:w+>/<action:w+>'=>'<controller>/<action>',
    ),
    'showScriptName'=>false,
),

我的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

将您的 .htaccess 文件更改为此文件

<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Don't perform redirects for files and directories that exist:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For everything else, redirect to index.php:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</ifModule>

注意:- 将其另存为 www/yourProject/.htaccess

最新更新