我正在完成 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/