php - Yii 404 错误,urlmanager showscript 为 false

标签 php apache .htaccess mod-rewrite yii

我正在完成 Yii 应用程序的工作,我想要有更漂亮的 URL。我通过谷歌搜索网站和 Yii wiki 并按照手册进行操作。然而,我陷入了无法从我的 URL 中隐藏 index.php 的困境。在我的网址中使用index.php,它可以工作,网站可以打开,没有它,它会给我服务器404。

这是我的 main.config:

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

将“showScriptName”设置为 false 时,我得到 404。

这是我的.htaccess

RewriteEngine on
RewriteBase /
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)

# otherwise forward it to index.php
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]

我目前正在使用 WAMP 在本地主机上测试该网站。 Apache 上的 Mod_rewrite 正在运行。将 http.conf 更改为选项索引 FollowSymLinks 允许覆盖全部。

我还缺少什么?

最佳答案

献给那些奋斗的人!将 .htaccess 放在应用程序的根目录中,而不是在 protected 文件夹中!!!

关于php - Yii 404 错误,urlmanager showscript 为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18930004/

相关文章:

php - 使用 MySQL INTO OUTFILE 不写入 tmp

php - 使用 PHP 检查数据库中是否存在外键

PHP代码没有被执行,但是代码显示在浏览器源代码中

php - SEO 友好的 URLs - 从 blog.php?articleId=26 到 blog/$articleTitle

javascript - PHP 'add more' 具有多类别过滤的链接

php - 如何使用 PHP 发送电子邮件?

通过 Internet 连接时,Apache 尝试连接到本地网络

java - 无法使用 apache poi 从 Excel 文件读取

php - 如何使用 .htaccess 删除 url 之间的扩展名

.htaccess 重定向 - 更新站点(301 合适?)