2012-10-09 72 views
0

我在codeigniter中有一個項目,我有一個.htaccess文件,我用來隱藏用戶的index.php頁面。在本地機器上,當項目是在Windows操作系統中,但是當我在linux(ubuntu發行版)中測試時.htaccess功能不起作用。任何關於我能爲linux做什麼的建議都非常感謝。 我的.htaccess文件:我的.htaccess文件有什麼問題,以便它可以在linux上工作?

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteBase /myproject/ 

    ### Canonicalize codeigniter URLs 

    # If your default controller is something other than 
    # "welcome" you should probably change this 
    RewriteRule ^(platform(/index)?)/?$/[L,R=301] 
    RewriteRule ^(.*)/index/?$ $1 [L,R=301] 

    # Removes trailing slashes (prevents SEO duplicate content issues) 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)/$ $1 [L,R=301] 

    # Enforce www 
    # If you have subdomains, you can add them to 
    # the list using the "|" (OR) regex operator 
    RewriteCond %{HTTP_HOST} !^(localhost|myproject) [NC] 
    RewriteRule ^(.*)$ http://localhost/myproject/$1 [L,R=301] 



    # Removes access to the system folder by users. 
    # Additionally this will allow you to create a System.php controller, 
    # previously this would not have been possible. 
    # 'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php/$1 [L] 

    # Checks to see if the user is attempting to access a valid file, 
    # such as an image or css document, if this isn't true it sends the 
    # request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L] 

</IfModule> 

<IfModule !mod_rewrite.c> 

    # Without mod_rewrite, route 404's to the front controller 
    ErrorDocument 404 /index.php 

</IfModule> 

回答

1

有許多原因,但那些我總是先檢查:

的AllowOverride

檢查主要的Apache配置。默認情況下,您的文檔根目錄的AllowOverride指令可能設置爲無。在這種情況下,Apache將忽略htaccess文件。

http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

模塊缺失

因爲你的命令,被包裹在一個IfModule聲明。如果您的Linux機器沒有該模塊,則該命令將不會被執行。

提示

要查看是否htacess正在讀取,只是把一些胡說八道的文件的頂部任何ifmodule語句,例如外「dkdkwei239d」或任何不是合法指令的內容。

您應該得到500服務器錯誤。如果沒有,那麼Apache不會讀取.htaccess文件。

如果您確實收到500錯誤,那麼Apache正在讀取該文件。

嘗試刪除Ifmodule語句。如果錯誤返回,那麼您可能會丟失重寫模塊。

+0

正當我在開始時添加此非字符串gfgfgfgfgfgfg appication崩潰服務器遇到內部錯誤或配置錯誤,無法完成您的請求。 請與服務器管理員webmaster @ localhost聯繫,並告知他們發生錯誤的時間以及您可能已經造成錯誤的任何事情。 有關此錯誤的更多信息可能在服務器錯誤日誌中可用。 http:// localhost/myproject上的Apache/2.2.22(Ubuntu)服務器端口49131 – user1718215

+0

因此,在Linux服務器上託管之後發生這種情況是很不可能的。然後爲了測試這個錯誤,我使用的是本地linux機器,錯誤是一樣的! – user1718215

相關問題