gpt4 book ai didi

apache - 如何从 Apache/Centos 中的 Yii URL 中删除 index.php?

转载 作者:行者123 更新时间:2023-12-04 23:23:56 26 4
gpt4 key购买 nike

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

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

LoadModule rewrite_module modules/mod_rewrite.so

我可以看到 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.

任何的想法?

最佳答案

我有同样的麻烦。
我使用 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

关于apache - 如何从 Apache/Centos 中的 Yii URL 中删除 index.php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16772044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com