从URL事业404警予删除的index.php [英] Removing index.php from URL cause 404 in yii
问题描述
问题
最初的问题:
您好我有,我想从URL中删除index.php的新发的Yii网站。结果
例如:/index.php/site/index应为/网站/指数
我一直用这个的http:/ /www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x 指导,但我只接收404
我希望你能指出错误或帮我调试这个问题!结果
请让我知道如果我离开了任何相关信息。
OBS:在家网页如预期运作,其他页面被打破
问题的现状:
现在看来似乎是mod_rewrite.so一个apache / Ubuntu的问题
答
这是不同的人的帮助后,这一切工作现在:D我必须安装rewrit,以让它运行,我也通过书面形式
运行a2enmod rewrit
我的系统的配置如下解决了这个问题对我来说,我希望这个线程将帮助其他人在类似的问题。
我的系统
服务器版本:阿帕奇/ 2.2.22(Ubuntu的)
Server内置:2012年11月8日21点37分45秒
Apache的httpd.conf
<目录/无功/网络/ MY_SITE / FOLDER_CONTAINING_YII />
所有的AllowOverride
#...
< /目录>
的LoadModule rewrite_module模块/ mod_rewrite.so
<青霉>这是该文件的全部内容的
Apache的错误日志
文件不存在:/.../htdocs/site,引用者:HTTP://.../htdocs/index.php/site/index
的我加了点的
重启Apache
KAH @ webaalborg:在/ etc / apache2的/网站可用$ sudo的服务重新启动的Apache2
*重新启动Web服务器的Apache2
[周一11月26日20点十六分35秒2012] [警告]模块rewrite_module已经加载,跳绳
等待...
[周一11月26日20点16分36秒2012] [警告]模块rewrite_module已经加载,跳绳
[ 好 ]
/等/ apache2的/可供网站/默认
...
的DocumentRoot的/ var / WWW
&LT;目录/&GT;
有FollowSymLinks
设置AllowOverride无
&LT; /目录&GT;
&LT;目录/ var / WWW /&GT;
选择指数多视图了FollowSymLinks
设置AllowOverride无
为了允许,拒绝
所有允许
&LT; /目录&GT;
&LT;目录/ var / WWW / MY_SITE&GT;
选择指数多视图了FollowSymLinks
所有的AllowOverride
为了允许,拒绝
所有允许
&LT; /目录&GT;
...
Yii的目录结构:
- 框架
- htdocs目录
- 资产
- CSS
- 的.htaccess
- 的index.php
- 索引test.php的
- 主题
- 保护
的.htaccess
RewriteEngine叙述上#如果目录或文件是否存在,直接使用它
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d#否则将其转发到index.php
重写规则。的index.php
main.php配置文件
'urlManager'=&GT;阵列(
网址格式'=&GT;'路',
showScriptName'=&GT;假的,
CASESENSITIVE'=&GT;假的,
规则= GT;阵列(
'&LT;控制器:\\ w +&GT; /&LT;编号:\\ D +&GT;'=&GT;'&LT;控制器与GT; /观点,
'&LT;控制器:\\ w +&GT; /&lt;作用:\\ w +&GT; /&LT;编号:\\ D +&GT;'=&GT;'&LT;控制器&GT; /&lt;作用&GT;,
'&LT;控制器:\\ w +&GT; /&lt;作用:\\ w +&GT;'=&GT;'&LT;控制器与GT; /&lt;作用&GT;,
)
)
如果您在Linux上工作(比如Ubuntu的),然后进入路径的/ etc / apache2的/网站的可用/
在那里你会发现一个名为默认
,
&LT;目录/ var / WWW /&GT; &LT; --- ***根目录***
选择指数多视图了FollowSymLinks
所有的AllowOverride LT&; ---- ***改变这一行***
为了允许,拒绝
所有允许
&LT; /目录&GT;
和我认为你的问题将解决。
感谢。
The problem
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"
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: The "home" page works as intended, other pages are broken.
Status of the problem: It seems like it is an apache/ubuntu problem with mod_rewrite.so
Answer
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.
My system
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
This is the entire content of the file
Apache Error Log
File does not exist: /.../htdocs/site, referer: http://.../htdocs/index.php/site/index
I added the dots
Restart Apache
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 Directory structure:
- framework
- htdocs
- assets
- css
- .htaccess
- index.php
- index-test.php
- themes
- protected
.htaccess
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 config file
'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>',
),
),
If you are working on Linux(say ubuntu) then go to the path /etc/apache2/sites-available/
there you will find a file named as default
,
<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.
Thanks.
这篇关于从URL事业404警予删除的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!