从 URL 中删除 index.php 导致 yii 中的 404
初始问题:我有一个新创建的 Yii 站点,我想从 URL 中删除 index.php.
例如:/index.php/site/index"应该是/site/index"
Initial problem:
Hi I have a newly made Yii site where I want to remove the index.php from the URL.
Example: "/index.php/site/index" should be "/site/index"
我一直在使用这个 http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x 指南,但我只收到 404.
I have been using this http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x guide but i only receive 404.
希望你能指出错误或帮我调试这个问题!
如果我遗漏了任何相关信息,请告诉我.
I hope that you are able to point a mistake or help me debug this problem!
Please let me know if I have left out any relevant information.
OBS:主页"按预期工作,其他页面损坏.
OBS: The "home" page works as intended, other pages are broken.
问题状态:似乎是 mod_rewrite.so 的 apache/ubuntu 问题
Status of the problem: It seems like it is an apache/ubuntu problem with mod_rewrite.so
在不同人的帮助下,现在一切正常:D我必须安装重写"才能让它运行,我是通过写作做到的运行 a2enmod 重写我系统的以下配置为我解决了这个问题,我希望这个帖子能帮助其他人解决类似的问题.
After help from different people it all works now :D I had to install "rewrit" to get it running, i did that by writing Running a2enmod rewrit The below configuration of my system solved the problem for me, I hope this thread will help others in similar problems.
Server version: Apache/2.2.22 (Ubuntu)
Server built: Nov 8 2012 21:37:45
Apache httpd.conf
<Directory "/var/www/MY_SITE/FOLDER_CONTAINING_YII/">
AllowOverride All
#...
</Directory>
LoadModule rewrite_module modules/mod_rewrite.so
这是文件的全部内容
File does not exist: /.../htdocs/site, referer: http://.../htdocs/index.php/site/index
我加了点
kah@webaalborg:/etc/apache2/sites-available$ sudo service apache2 restart
* Restarting web server apache2
[Mon Nov 26 20:16:35 2012] [warn] module rewrite_module is already loaded, skipping
... waiting
[Mon Nov 26 20:16:36 2012] [warn] module rewrite_module is already loaded, skipping
[ OK ]
/ect/apache2/available-sites/default
...
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /var/www/MY_SITE>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
...
Yii 目录结构:
- 框架
- htdocs
- 资产
- css
- .htaccess
- index.php
- index-test.php
- 主题
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
main.php 配置文件
'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'caseSensitive'=>false, 'rules'=>array( '<controller:w+>/<id:d+>'=>'<controller>/view', '<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>', '<controller:w+>/<action:w+>'=>'<controller>/<action>', ), ),
推荐答案
如果你在 Linux(比如 ubuntu)上工作,那么转到路径
/etc/apache2/sites-available/
那里你会找到一个名为default
,If you are working on Linux(say ubuntu) then go to the path
/etc/apache2/sites-available/
there you will find a file named asdefault
,<Directory /var/www/> <--- ***root directory*** Options Indexes FollowSymLinks MultiViews AllowOverride all <---- ***change this line*** Order allow,deny allow from all </Directory>
我认为你的问题会解决.
and i think your problem will resolve.
谢谢.
相关文章