[英]Yii removing index.php using htaccess gives me 404 error
I removed index.php from my url using htaccess as mentioned in Yii forums/guide.It was working fine on my Windows PC with Xampp installed in it.But when i uploaded it in on y shared hosting only home page is loading.All the other links are getting 404 error. 如Yii论坛/指南中所述,我使用htaccess从url中删除了index.php。它在装有Xampp的Windows PC上运行良好,但是当我将其上传到y共享主机上时,仅加载主页。其他链接出现404错误。
My .Htaccess 我的.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
When i contacted my hosting support team they told mode_rewrite is enabled. 当我与托管支持团队联系时,他们告诉我mode_rewrite已启用。
My main.config content is 我的main.config内容是
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'gii' => 'gii/<controller>',
'admin' => 'admin/default/index',
'admin/<controller:\w+>' => 'admin/<controller>',
'admin/<controller:\w+>/<action:\w+>/<id:\d+>'=>'admin/<controller>/<action>',
'admin/<controller:\w+>/<action:\w+>'=>'admin/<controller>/<action>',
'gii' => 'gii/default/index',
'gii/<controller:\w+>' => 'gii/<controller>',
'gii/<controller:\w+>/<action:\w+>/<id:\d+>'=>'gii/<controller>/<action>',
'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>',
),
'showScriptName'=>false,
),
I tried numerous solutions,but all in vain.Please help 我尝试了许多解决方案,但都徒劳无功。请帮助
Try RewriteRule . /index.php
尝试
RewriteRule . /index.php
RewriteRule . /index.php
instead, watch the starting slash. RewriteRule . /index.php
,请注意起始斜杠。
Otherwise the path is relative, so http://somedomain.com/path/
would be redirected to http://somedomain.com/path/index.php
, instead of http://somedomain.com/index.php
. 否则,该路径是相对的,所以
http://somedomain.com/path/
将被重定向到http://somedomain.com/path/index.php
,而不是http://somedomain.com/index.php
。
Url manager in config file must be like this 配置文件中的网址管理器必须是这样的
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'home' => '/site/index',
'cms' => '/site/contentview',
'register' => '/site/register',
'login' => '/site/login',
......),
),
And the .htaccess must be like this .htaccess必须像这样
Options +FollowSymLinks
IndexIgnore */*
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
The most common problem when copying from localhost (windows or Mac) to sever (linux) is the case sensitivity, check your case on the controllers. 从本地主机(Windows或Mac)复制到服务器(Linux)时,最常见的问题是区分大小写,请在控制器上检查大小写。
Also, check for the AllowOverride
directive inside the definition of your virtualhost. 另外,检查虚拟主机定义中的
AllowOverride
指令。
<Directory /path/to/website>
AllowOverride All
Require all granted
</Directory>
otherwise the rewrite rules will have no effect even when mod_rewrite
is enabled. 否则,即使启用了
mod_rewrite
,重写规则也不会生效。
Source: http://www.yiiframework.com/forum/index.php/topic/30739-404-errors-on-apache2-ubuntu/page__p__148021__hl__404+error#entry148021 来源: http : //www.yiiframework.com/forum/index.php/topic/30739-404-errors-on-apache2-ubuntu/page__p__148021__hl__404+error#entry148021
我经历了同样的问题,请检查您是否遵循了控制器M Yçontroller第一的Lettre且必须是大写控制器的“C”的命名约定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.