[英]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.