Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Apache/Centos中从Yii URL中删除index.php?_Apache_.htaccess_Mod Rewrite_Yii - Fatal编程技术网

如何在Apache/Centos中从Yii URL中删除index.php?

如何在Apache/Centos中从Yii URL中删除index.php?,apache,.htaccess,mod-rewrite,yii,Apache,.htaccess,Mod Rewrite,Yii,我正在使用Apache/2.2.15(CentOS)服务器上的Yii框架 以下行在/etc/httpd/conf/httpd.conf中未注释 当我执行以下操作时,我可以在加载的模块下看到模块重写 Yii项目结构: /var/www/test/ /var/www/test/index.php /var/www/test/.htaccess http://10.20.30.40/test/index.php/testcontroller/testaction http://10.2

我正在使用Apache/2.2.15(CentOS)服务器上的Yii框架


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


当我执行以下操作时,我可以在加载的模块下看到模块重写


Yii项目结构:

/var/www/test/ 
/var/www/test/index.php 
/var/www/test/.htaccess
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.

.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

我这样做时效果很好:

/var/www/test/ 
/var/www/test/index.php 
/var/www/test/.htaccess
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.

但当我这样做时:

/var/www/test/ 
/var/www/test/index.php 
/var/www/test/.htaccess
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.
它显示以下错误:

/var/www/test/ 
/var/www/test/index.php 
/var/www/test/.htaccess
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.
有什么想法吗

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>'),
'urlManager'=>数组(
“urlFormat”=>“路径”,
'showScriptName'=>false,
'规则'=>数组(
“/”=>“/视图”,
'//' => '/',
'/' => '/'),

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

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

我也遇到同样的问题。 我使用Apache配置别名,如:

<VirtualHost *:80>
...

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

...
</VirtualHost>

...
别名/项目“/用户/foo/Sites/project”
...
为了解决这个问题,我在.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
重新编写引擎打开

RewriteBase/project#我在编辑Apache配置文件时解决了这个问题:

{{ApacheDir}}/conf/httpd.conf

和取消注释/添加以下行:

LoadModule rewrite_module modules/mod_rewrite.so

阅读主题。它会很有用。@Awan您解决了这个问题吗?我有同样的问题,如果您解决了,请帮助我。谢谢+1:)