4

我在Apache/2.2.15 (CentOS) Server上使用Yii 框架


以下行在/etc/httpd/conf/httpd.conf中未注释

LoadModule rewrite_module modules/mod_rewrite.so


当我执行以下操作时,我可以在Loaded Module下看到mod_rewrite

<?php phpinfo(); ?>


Yii 项目结构:

/var/www/test/ 
/var/www/test/index.php 
/var/www/test/.htaccess


.htaccess 内容

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


当我这样做时它工作正常:

http://10.20.30.40/test/index.php/testcontroller/testaction


但是当我这样做时:

http://10.20.30.40/test/testcontroller/testaction

它显示以下错误:

Not Found

The requested URL /var/www/test/index.php was not found on this server.

任何想法?

4

4 回答 4

4

我有同样的麻烦。我使用 Apache 配置别名,例如:

<VirtualHost *:80>
...

Alias /project "/Users/foo/Sites/project"

...
</VirtualHost>

为了解决,我在 .htaccess 上使用“RewriteBase”指令,例如:

RewriteEngine on
RewriteBase /project # <---- Modify here! and remove this comment.

# 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

来源:http ://www.yiiframework.com/wiki/214/url-hide-index-php/#c9725

于 2013-10-26T23:28:41.190 回答
2

确保 httpd.conf 中项目 Web 目录的 AllowOverride 为“All”。如果不是,请更改该值并重新启动 Web 服务器

于 2013-10-10T03:56:21.420 回答
2
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

htaccess 内容。

'urlManager' => array(
    'urlFormat' => 'path',
    'showScriptName' => false,
    'rules' => array(
        '<controller:\w+>/<id:\d+>' => '<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
        '<controller:\w+>/<action:\w+>' => '<controller>/<action>'),

main.php 中的 urlmanager 配置。或者,您可以根据需要自定义它。

于 2013-05-27T11:46:42.070 回答
0

我在以下位置解决了编辑 Apache 配置文件的问题: {{ApacheDir}}/conf/httpd.conf
并取消注释/添加以下行: LoadModule rewrite_module modules/mod_rewrite.so

于 2014-09-12T05:41:47.057 回答