2012-04-10 61 views
0

我用笨顯示阻止的文件,我試圖通過創建.htaccess文件 刪除從URL的index.php和它的內容:拆卸時從URL(笨)的index.php的.htaccess從

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

這種方式是在xampp服務器上工作。 但我上傳的網站,不幸有一個問題出現:

我有一個文件夾稱爲文件和它的內容子文件夾:圖像,CSS,JS,SWF,上傳。 並且這些文件夾中的每個文件都無法查看,並且瀏覽器在那裏顯示找不到該文件。

任何幫助ploese。

+0

錯誤日誌告訴你什麼? – Sedz 2012-04-10 13:39:13

回答

1

試試這個,我認爲會解決你的問題..

RewriteEngine on 
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

你要告訴你的服務器沒有結束來處理這些目錄的index.php和線,對這項工作是:

RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload) 
+0

感謝所有我用過的最後一個工作文件。但我應該把所有的子目錄?因爲我有另一個網站,我有一個文件夾有很多子目錄,我試圖把主要目錄的名稱存在index.php附近,它沒有工作。 – 2012-04-10 23:12:36

+0

是的,你應該包括你不想讓PHP處理的所有子文件夾/文件夾。 – zaherg 2012-04-11 04:53:23

2

只要確保你排除那些太:

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt|css|swf|upload) 
RewriteRule ^(.*)$ /index.php/$1 [L] 
1

這裏是我的.htaccess文件 - 這應該爲你工作:

Options -Indexes 
Options +FollowSymLinks 

# Set the default file for indexes 
DirectoryIndex index.php 

<IfModule mod_rewrite.c> 

    # activate URL rewriting 
    RewriteEngine on 

    # do not rewrite links to the documentation, assets and public files 
    RewriteCond $1 !^(files|css|js|swfimages|assets|uploads|captcha) 

    # do not rewrite for php files in the document root, robots.txt or the maintenance page 
    RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml|maintenance\.html) 

    # but rewrite everything else 
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    ErrorDocument 404 index.php 
</IfModule> 
2

這是我的.htaccess文件。我的理解是,對於任何試圖訪問但不存在的文件或目錄,它將轉發到Codeigniter。

確實存在的任何東西都可以正常工作,並且不需要單獨排除。這樣可以節省時間,並且每次添加新的目錄或文件夾時都不會有問題,因爲它不會要求您編輯此文件。

RewriteEngine on 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [L] 

適用於我們,但我的理解可能不正確。希望它可以幫助

+0

謝謝。這工作得很好。 我有另一個網站和下一個index.php我有一個文件夾稱爲文件,這一個內容很多的文件夾,我必須把他們的所有名稱和子目錄名稱在他們? – 2012-04-10 23:24:43

+0

不知道爲什麼這不是更多upvoted,這是迄今爲止最好的解決方案。 – StackOverflowed 2012-09-10 04:07:15

1

謝謝。這工作得很好:

RewriteEngine on 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [L] 

我還有一個網站,未來的index.php我有一個文件夾名爲文件和文件夾的這一個內容很多,我應該已經把子目錄它們的所有地名和地名中他們?