簡體   English   中英

從URL中刪除index.php導致yii中的404

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

Apache httpd.conf

<Directory "/var/www/MY_SITE/FOLDER_CONTAINING_YII/">
AllowOverride All
#...
</Directory>
LoadModule rewrite_module modules/mod_rewrite.so

這是文件的全部內容

Apache錯誤日志

File does not exist: /.../htdocs/site, referer: http://.../htdocs/index.php/site/index  

我加了點

重啟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的/可用的網站/默認

...
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
    • 指數型的test.php
    • 主題
  • 保護

的.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配置文件

'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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM