[英]Removing index.php from URL cause 404 in yii
最初的问题:您好我有一个新建的Yii网站,我想从URL中删除index.php。
示例:“/ index.php / site / index”应为“/ site / index”
我一直在使用这个http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x指南,但我只收到404。
我希望你能指出一个错误或帮我调试这个问题!
如果我遗漏了任何相关信息,请告诉我。
OBS:“主页”页面按预期工作,其他页面被破坏。
问题的状态:看起来这是mod_rewrite.so的apache / ubuntu问题
在得到不同人的帮助后,它现在全部工作了:DI必须安装“重写”才能让它运行,我通过编写运行a2enmod重写这样做我的系统的下面配置解决了我的问题,我希望这个线程能帮助其他人类似的问题。
Server version: Apache/2.2.22 (Ubuntu)
Server built: Nov 8 2012 21:37:45
<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 ]
...
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>
...
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
'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
的文件,
<Directory /var/www/> <--- ***root directory***
Options Indexes FollowSymLinks MultiViews
AllowOverride all <---- ***change this line***
Order allow,deny
allow from all
</Directory>
我认为你的问题会解决。
谢谢。
你的目录指令中是否允许AllowOverride
?
<Directory "/your/path">
AllowOverride All
#...
</Directory>
如果没有,这将解释为什么你的重写规则不起作用。
试着将它放入.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
并从httpd.conf中删除“LoadModule rewrite_module modules / mod_rewrite.so”行,并从命令行启用重写模块,执行a2enmod重写。
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all <---- ***change this line***
Order allow,deny <---- ***change this line***
allow from all
Require all granted
</Directory>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.